var newGame4MinusRespeccedVersion = 2.9
/*
var temp=Math.log10;
Math.log10=(function(a){if(a<0)debugger;b=this;return b(a);}).bind(temp);
var temp=Math.log;
Math.log=(function(a){if(a<0)debugger;b=this;return b(a);}).bind(temp);
var temp=Math.log2;
Math.log2=(function(a){if(a<0)debugger;b=this;return b(a);}).bind(temp);
var temp=Decimal.log10;
Decimal.log10=(function(a){if(a.lt(0))debugger;b=this;return b(a);}).bind(temp);
var temp=Decimal.log;
Decimal.log=(function(a){if(a.lt(0))debugger;b=this;return b(a);}).bind(temp);
var temp=Decimal.log2;
Decimal.log2=(function(a){if(a.lt(0))debugger;b=this;return b(a);}).bind(temp);
*/
//test
var diffMultiplier = 1
var gameLoopIntervalId;
var Marathon = 0;
var Marathon2 = 0;
var auto = false;
var autoS = true;
var shiftDown = false;
var controlDown = false;
var justImported = false;
var saved = 0;
var painTimer = 0;
var keySequence = 0;
var failureCount = 0;
var implosionCheck = 0;
var TIER_NAMES = [ null, "first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eight" ];
var DISPLAY_NAMES = [ null, "First", "Second", "Third", "Fourth", "Fifth", "Sixth", "Seventh", "Eighth" ];
var forceHardReset = false;
var player = {
    money: new Decimal(10),
    tickSpeedCost: new Decimal(1000),
    tickspeed: new Decimal(10000),
    firstCost: new Decimal(10),
    secondCost: new Decimal(100),
    thirdCost: new Decimal(10000),
    fourthCost: new Decimal(1000000),
    fifthCost: new Decimal(1e9),
    sixthCost: new Decimal(1e13),
    seventhCost: new Decimal(1e18),
    eightCost: new Decimal(1e24),
    firstAmount: new Decimal(0),
    secondAmount: new Decimal(0),
    thirdAmount: new Decimal(0),
    fourthAmount: new Decimal(0),
    firstBought: 0,
    secondBought: 0,
    thirdBought: 0,
    fourthBought: 0,
    firstTotalBought: 0,
    secondTotalBought: 0,
    thirdTotalBought: 0,
    fourthTotalBought: 0,
    fifthAmount: new Decimal(0),
    sixthAmount: new Decimal(0),
    seventhAmount: new Decimal(0),
    eightAmount: new Decimal(0),
    fifthBought: 0,
    sixthBought: 0,
    seventhBought: 0,
    eightBought: 0,
    fifthTotalBought: 0,
    sixthTotalBought: 0,
    seventhTotalBought: 0,
    eightTotalBought: 0,
    firstPow: new Decimal(1),
    secondPow: new Decimal(1),
    thirdPow: new Decimal(1),
    fourthPow: new Decimal(1),
    fifthPow: new Decimal(1),
    sixthPow: new Decimal(1),
    seventhPow: new Decimal(1),
    eightPow: new Decimal(1),
    sacrificed: new Decimal(0),
    achievements: [],
    infinityUpgrades: [],
    challenges: [],
    currentChallenge: "",
    infinityPoints: new Decimal(0),
    infinitied: 0,
    infinitiedBank: 0,
    totalTimePlayed: 0,
    bestInfinityTime: 9999999999,
    thisInfinityTime: 0,
    resets: 0,
    galaxies: 0,
    tickDecrease: 0.9,
    totalmoney: new Decimal(0),
    achPow: 1,
    newsArray: [],
    interval: null,
    lastUpdate: new Date().getTime(),
    autobuyers: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
    costMultipliers: [new Decimal(1e3), new Decimal(1e4), new Decimal(1e5), new Decimal(1e6), new Decimal(1e8), new Decimal(1e10), new Decimal(1e12), new Decimal(1e15)],
    tickspeedMultiplier: new Decimal(10),
    chall2Pow: 1,
    chall3Pow: new Decimal(0.01),
    matter: new Decimal(0),
    chall11Pow: new Decimal(1),
    partInfinityPoint: 0,
    partInfinitied: 0,
    break: false,
    challengeTimes: [600*60*24*31, 600*60*24*31, 600*60*24*31, 600*60*24*31, 600*60*24*31, 600*60*24*31, 600*60*24*31, 600*60*24*31, 600*60*24*31, 600*60*24*31, 600*60*24*31, 600*60*24*31, 600*60*24*31],
    infchallengeTimes: [600*60*24*31, 600*60*24*31, 600*60*24*31, 600*60*24*31, 600*60*24*31, 600*60*24*31, 600*60*24*31, 600*60*24*31, 600*60*24*31, 600*60*24*31, 600*60*24*31, 600*60*24*31, 600*60*24*31, 600*60*24*31, 600*60*24*31, 600*60*24*31, 600*60*24*31, 600*60*24*31, 600*60*24*31, 600*60*24*31],
    lastTenRuns: [[600*60*24*31, 1], [600*60*24*31, 1], [600*60*24*31, 1], [600*60*24*31, 1], [600*60*24*31, 1], [600*60*24*31, 1], [600*60*24*31, 1], [600*60*24*31, 1], [600*60*24*31, 1], [600*60*24*31, 1]],
    lastTenEternities: [[600*60*24*31, 1], [600*60*24*31, 1], [600*60*24*31, 1], [600*60*24*31, 1], [600*60*24*31, 1], [600*60*24*31, 1], [600*60*24*31, 1], [600*60*24*31, 1], [600*60*24*31, 1], [600*60*24*31, 1]],
    infMult: new Decimal(1),
    infMultCost: new Decimal(10),
    tickSpeedMultDecrease: 10,
    tickSpeedMultDecreaseCost: 3e6,
    dimensionMultDecrease: 10,
    dimensionMultDecreaseCost: 1e8,
    overXGalaxies: 10,
    version: 13,
    infDimensionsUnlocked: [false, false, false, false, false, false, false, false],
    infinityPower: new Decimal(1),
    spreadingCancer: 0,
    postChallUnlocked: 0,
    postC6Tier: 0,
    postC3Reward: new Decimal(1),
    eternityPoints: new Decimal(0),
    eternities: 0,
    thisEternity: 0,
    bestEternity: 9999999999,
    eternityUpgrades: [],
    epmult: new Decimal(1),
    epmultCost: new Decimal(500),
    infinityDimension1 : {
        cost: new Decimal(1e8),
        amount: new Decimal(0),
        bought: 0,
        power: new Decimal(1),
        baseAmount: 0
    },
    infinityDimension2 : {
        cost: new Decimal(1e9),
        amount: new Decimal(0),
        bought: 0,
        power: new Decimal(1),
        baseAmount: 0
    },
    infinityDimension3 : {
        cost: new Decimal(1e10),
        amount: new Decimal(0),
        bought: 0,
        power: new Decimal(1),
        baseAmount: 0
    },
    infinityDimension4 : {
        cost: new Decimal(1e20),
        amount: new Decimal(0),
        bought: 0,
        power: new Decimal(1),
        baseAmount: 0
    },
    infinityDimension5 : {
        cost: new Decimal(1e140),
        amount: new Decimal(0),
        bought: 0,
        power: new Decimal(1),
        baseAmount: 0
    },
    infinityDimension6 : {
        cost: new Decimal(1e200),
        amount: new Decimal(0),
        bought: 0,
        power: new Decimal(1),
        baseAmount: 0
    },
    infinityDimension7 : {
        cost: new Decimal(1e250),
        amount: new Decimal(0),
        bought: 0,
        power: new Decimal(1),
        baseAmount: 0
    },
    infinityDimension8 : {
        cost: new Decimal(1e280),
        amount: new Decimal(0),
        bought: 0,
        power: new Decimal(1),
        baseAmount: 0
    },
    infDimBuyers: [false, false, false, false, false, false, false, false],
    timeShards: new Decimal(0),
    tickThreshold: new Decimal(1),
    totalTickGained: 0,
    timeDimension1: {
        cost: new Decimal(1),
        amount: new Decimal(0),
        power: new Decimal(1),
        bought: 0,
		
        costAntimatter: new Decimal(1),
        boughtAntimatter: 0,
    },
    timeDimension2: {
        cost: new Decimal(5),
        amount: new Decimal(0),
        power: new Decimal(1),
        bought: 0,
		
        costAntimatter: new Decimal(1),
        boughtAntimatter: 0,
    },
    timeDimension3: {
        cost: new Decimal(100),
        amount: new Decimal(0),
        power: new Decimal(1),
        bought: 0,
		
        costAntimatter: new Decimal(1),
        boughtAntimatter: 0,
    },
    timeDimension4: {
        cost: new Decimal(1000),
        amount: new Decimal(0),
        power: new Decimal(1),
        bought: 0,
		
        costAntimatter: new Decimal(1),
        boughtAntimatter: 0,
    },
    timeDimension5: {
        cost: new Decimal("1e2350"),
        amount: new Decimal(0),
        power: new Decimal(1),
        bought: 0,
		
        costAntimatter: new Decimal(1),
        boughtAntimatter: 0,
    },
    timeDimension6: {
        cost: new Decimal("1e2650"),
        amount: new Decimal(0),
        power: new Decimal(1),
        bought: 0,
		
        costAntimatter: new Decimal(1),
        boughtAntimatter: 0,
    },
    timeDimension7: {
        cost: new Decimal("1e3000"),
        amount: new Decimal(0),
        power: new Decimal(1),
        bought: 0,
		
        costAntimatter: new Decimal(1),
        boughtAntimatter: 0,
    },
    timeDimension8: {
        cost: new Decimal("1e3350"),
        amount: new Decimal(0),
        power: new Decimal(1),
        bought: 0,
		
        costAntimatter: new Decimal(1),
        boughtAntimatter: 0,
    },
    offlineProd: 0,
    offlineProdCost: 1e7,
    extraDimPowerIncrease: 0,
    dimPowerIncreaseCost: new Decimal(1e3),
    challengeTarget: 0,
    replicanti: {
        amount: new Decimal(0),
        unl: false,
        chance: 0.01,
        chanceCost: new Decimal(1e90),
        interval: 1000,
        intervalCost: new Decimal(1e80),
        gal: 0,
        galaxies: 0,
        galCost: new Decimal(1e110),
        auto: [false, false, false]
    },
    timestudy: {
        theorem: 0,
        amcost: new Decimal("1e20000"),
        ipcost: new Decimal(1),
        epcost: new Decimal(1),
        studies: [],
    },
    eternityChalls: {},
    eternityChallGoal: new Decimal(Number.MAX_VALUE),
    currentEternityChall: "",
    eternityChallUnlocked: 0,
    etercreq: 0,
    autoIP: new Decimal(0),
    autoTime: 1e300,
    infMultBuyer: false,
    autoCrunchMode: "amount",
    respec: false,
    eternityBuyer: {
        limit: new Decimal(0),
        isOn: false
    },
    eterc8ids: 50,
    eterc8repl: 40,
    tickBoughtThisInf: {
      current: 0,
      pastResets: [{'resets': 0, 'bought': 0}]
    },
    dimlife: true,
    dead: true,
    dilation: {
        studies: [],
        active: false,
        tachyonParticles: new Decimal(0),
        dilatedTime: new Decimal(0),
        totalTachyonParticles: new Decimal(0),
        nextThreshold: new Decimal(1000),
        freeGalaxies: 0,
        upgrades: [],
        rebuyables: {
            1: 0,
            2: 0,
            3: 0,
        }
    },
    why: 0,
    galacticSacrifice: {
      galaxyPoints: new Decimal(0),
      last: Date.now(),
      times: 0,
      upgrades: []
    },
    options: {
        newsHidden: false,
        notation: "Mixed scientific",
        //Standard = normal prefixed numbers, Scientific = standard form, Engineering = powers of 3.
        scientific: false,
        challConf: false,
        sacrificeConfirmation: true,
        gSacrificeConfirmation: true,
        retryChallenge: false,
        bulkOn: true,
        cloud: true,
        hotkeys: true,
        theme: undefined,
        secretThemeKey: 0,
        eternityconfirm: true,
        commas: true,
        updateRate: 50,
        chart: {
            updateRate: 1000,
            duration: 10,
            warning: 0,
        },
        animations: {
            floatingText: true,
            bigCrunch: true,
            eternity: true,
            tachyonParticles: true,
        },
        // we can detect saves from other variants (unless they specifically try)
        ngminusminus: true
    },
	
	// for aarex modifications
	aarexModifications: {
		ngmX: 4,
		ngmm: 3,
		ngm4r: 1,
		newGame4MinusRespeccedVersion: newGame4MinusRespeccedVersion
	},
	
	tickspeedBoosts: 0,
	tdBoosts: 0,

    timeless: {
        active: false,
        shards: new Decimal(0),
        points: new Decimal(0),
        upgrades: [],
        rebuyables: {
        }
    },
};


var defaultStart = $.extend(true, {}, player);





function setTheme(name) {
    document.querySelectorAll("link").forEach( function(e) {
        if (e.href.includes("theme")) e.remove();
    });

    if(name !== undefined && name.length < 3) giveAchievement("Shhh... It's a secret")
    if(name === undefined) {
        document.getElementById("theme").textContent = "Current theme: Normal"
    } else if(name === "S1") {
        document.getElementById("theme").textContent="Current theme: " + player.options.secretThemeKey;
        Chart.defaults.global.defaultFontColor = 'black';
        normalDimChart.data.datasets[0].borderColor = '#000'
    } else if(name === "S2") {
        document.getElementById("theme").textContent="Current theme: " + player.options.secretThemeKey;
        Chart.defaults.global.defaultFontColor = 'black';
        normalDimChart.data.datasets[0].borderColor = '#000'
    } else if(name === "S3") {
        document.getElementById("theme").textContent="Current theme: " + player.options.secretThemeKey;
        Chart.defaults.global.defaultFontColor = 'black';
        normalDimChart.data.datasets[0].borderColor = '#000'
    } else if(name === "S4") {
        document.getElementById("theme").textContent="Current theme: " + player.options.secretThemeKey;
        Chart.defaults.global.defaultFontColor = 'black';
        normalDimChart.data.datasets[0].borderColor = '#000'
    }  else if(name === "S5") {
        document.getElementById("theme").textContent="Current theme: " + player.options.secretThemeKey;
        Chart.defaults.global.defaultFontColor = 'black';
        normalDimChart.data.datasets[0].borderColor = '#000'
    } else {
        document.getElementById("theme").textContent="Current theme: " + name;
    }

    if (name === undefined) return;

    var head = document.head;
    var link = document.createElement('link');

    link.type = 'text/css';
    link.rel = 'stylesheet';
    link.href = "stylesheets/theme-" + name + ".css";

    head.appendChild(link);
}

document.getElementById("theme").onclick = function () {
    if (player.options.theme === undefined) {
        player.options.theme = "Metro";
    } else if (player.options.theme === "Metro") {
        player.options.theme = "Dark";
        Chart.defaults.global.defaultFontColor = '#888';
        normalDimChart.data.datasets[0].borderColor = '#888'
    } else if (player.options.theme === "Dark") {
        player.options.theme = "Dark Metro";
    } else if (player.options.theme === "Dark Metro") {
        player.options.theme = "Inverted";
        Chart.defaults.global.defaultFontColor = 'black';
        normalDimChart.data.datasets[0].borderColor = '#000'
    } else if (player.options.theme === "Inverted") {
        player.options.theme = "Inverted Metro";
    } else {
        player.options.theme = undefined;
        Chart.defaults.global.defaultFontColor = 'black';
        normalDimChart.data.datasets[0].borderColor = '#000'
    }

    setTheme(player.options.theme);

}


let kongIPMult = 1
let kongDimMult = 1
let kongAllDimMult = 1
let kongEPMult = 1








function showTab(tabName) {
    //iterate over all elements in div_tab class. Hide everything that's not tabName and show tabName
    var tabs = document.getElementsByClassName('tab');
    var tab;
    for (var i = 0; i < tabs.length; i++) {
        tab = tabs.item(i);
        if (tab.id === tabName) {
            tab.style.display = 'block';
        } else {
            tab.style.display = 'none';
        }
    }
    if (document.getElementById("timestudies").style.display != "none" && document.getElementById("eternitystore").style.display != "none") document.getElementById("TTbuttons").style.display = "block";
    else document.getElementById("TTbuttons").style.display = "none"
    if (document.getElementById("antimatterdimensions").style.display != "none" && document.getElementById("dimensions").style.display != "none") document.getElementById("progress").style.display = "block";
    else document.getElementById("progress").style.display = "none"
    resizeCanvas();
    closeToolTip();
}




function updateMoney() {
    var element = document.getElementById("coinAmount");
    element.textContent = formatValue(player.options.notation, player.money, 2, 1);
    var element2 = document.getElementById("matter");
    if (player.currentChallenge == "challenge12" || player.currentChallenge == "postc4" || player.currentChallenge == "postc8") element2.textContent = "There is " + formatValue(player.options.notation, player.matter, 2, 1) + " matter."
    var element3 = document.getElementById("chall13Mult");
    if (player.currentChallenge === "challenge13" || player.currentChallenge === "postc4" || player.currentChallenge === "postcngm3_3" || player.challenges.includes("postcngm3_3")) element3.innerHTML = formatValue(player.options.notation, productAllTotalBought(), 2, 1) + ' multiplier on all dimensions (product of bought'+(player.challenges.includes("postcngm4r_2")?'^15':'')+').';
	
	document.getElementById("dilationEffect1").textContent = "Dilation Effect: exponent ^"+getDilationPower().toFixed(4)
}

function updateCoinPerSec() {
    var element = document.getElementById("coinsPerSec");
    if (player.currentChallenge == "challenge3" || player.currentChallenge == "postc4") {
      element.textContent = 'You are getting ' + shortenDimensions(getDimensionProductionPerSecond(1).times(player.chall3Pow)) + ' antimatter per second.'
    } else if (player.currentChallenge == "challenge7" || player.currentChallenge == "postcngm3_3") {
      element.textContent = 'You are getting ' + (shortenDimensions(getDimensionProductionPerSecond(1).plus(getDimensionProductionPerSecond(2)))) + ' antimatter per second.'
    } else {
      element.textContent = 'You are getting ' + shortenDimensions(getDimensionProductionPerSecond(1)) + ' antimatter per second.'
    }
}

function getInfinitied() {return Math.max(player.infinitied + player.infinitiedBank, 0)}




function getGalaxyCostScalingStart4() {
	if (player.currentEternityChall == "eterc5" || player.currentChallenge == "postcngm4r_4")return 0
    var n = 40 + ECTimesCompleted("eterc5")*2
    if (player.timestudy.studies.includes(223)) n += 7
    if (player.timestudy.studies.includes(224)) n += player.resets/2000
	
    return n
}

function getGalaxyCostScalingStart5() {
    var n = 50
	
    return n
}

function getScalingSpeed(){
	let ret = 1;
	if (player.galaxies >= getGalaxyCostScalingStart5()) { // ghostly
        ret = Math.pow(2, (player.galaxies + 1 - getGalaxyCostScalingStart5()) / 50);
    }
	if (player.currentEternityChall == "eterc5")ret=ret*5;
	return ret;
}

function getDarkMatterGalaxiesStrength(){
	let ret=1;
	if(player.timeless.upgrades.includes(22))ret=ret*0.8;
	ret *= getScalingSpeed();
	return ret;
}

function getGalaxyCostScalingStart() {
	if (player.currentEternityChall == "eterc5" || player.currentChallenge == "postcngm4r_4")return 0
    var n = 10 + ECTimesCompleted("eterc5")*2
    if (player.timestudy.studies.includes(223)) n += 7
    if (player.timestudy.studies.includes(224)) n += player.resets/2000
	
	if(player.challenges.includes("postc7"))n = n + 5;
	if (player.achievements.includes("r83"))n = n + 1;
		
    if (player.galaxies >= getGalaxyCostScalingStart4()) { // dark matter galaxies
        n -= ((player.galaxies-getGalaxyCostScalingStart4()+1) * getDarkMatterGalaxiesStrength())
    }
    return n
}

function getGalaxyCostScalingStart2() {
	if (player.currentEternityChall == "eterc5" || player.currentChallenge == "postcngm4r_4")return 0
    var n = 20 + ECTimesCompleted("eterc5")*2
    if (player.timestudy.studies.includes(223)) n += 7
    if (player.timestudy.studies.includes(224)) n += player.resets/2000
		
	if (player.achievements.includes("r83"))n = n + 1;
    if (player.galaxies >= getGalaxyCostScalingStart4()) { // dark matter galaxies
        n -= ((player.galaxies-getGalaxyCostScalingStart4()+1) * getDarkMatterGalaxiesStrength())
    }
    return n
}

function getGalaxyCostScalingStart3() {
	if (player.currentEternityChall == "eterc5" || player.currentChallenge == "postcngm4r_4")return 0
    var n = 30 + ECTimesCompleted("eterc5")*2
    if (player.timestudy.studies.includes(223)) n += 7
    if (player.timestudy.studies.includes(224)) n += player.resets/2000
	
	if (player.achievements.includes("r83"))n = n + 1;
    if (player.galaxies >= getGalaxyCostScalingStart4()) { // dark matter galaxies
        n -= ((player.galaxies-getGalaxyCostScalingStart4()+1) * getDarkMatterGalaxiesStrength())
    }
    return n
}

function getGalaxyCostIncrease() {
  if (player.currentChallenge === 'postc1') return 60;
  let ret = 60;
  if (player.galacticSacrifice.upgrades.includes(22)) {
    ret = 50;
  }
  if (player.currentChallenge == "challenge4") {
    ret = 90;
  }
  if (player.infinityUpgrades.includes("galCost")) {
    ret -= 5;
  }
  if (player.infinityUpgrades.includes("postinfi52")) ret -= 3
  if (player.timestudy.studies.includes(42)) ret -= 6
  return ret;
}

function getGalaxyRequirement() {
    let base = ((player.galaxies) * getGalaxyCostIncrease());
    let amount = 40 + base;
    if (player.galacticSacrifice.upgrades.includes(22) && player.galaxies > 0) {
      amount -= 30;
    }
    if (player.currentChallenge == "challenge4") amount = 99 + base;
	
	
	let scalingspd = getScalingSpeed();
	
    let galaxyCostScalingStart = getGalaxyCostScalingStart()
    let galaxyCostScalingStart2 = getGalaxyCostScalingStart2()
    let galaxyCostScalingStart3 = getGalaxyCostScalingStart3()
    let galaxyCostScalingStart4 = getGalaxyCostScalingStart4()
    let galaxyCostScalingStart5 = getGalaxyCostScalingStart5()
	
	
	
    if (player.galaxies >= galaxyCostScalingStart) { // distant
        amount += (player.galaxies - galaxyCostScalingStart) * (player.galaxies - galaxyCostScalingStart+1) * scalingspd
    }
	
    if (player.galaxies >= galaxyCostScalingStart2) { // further
        amount += (player.galaxies - galaxyCostScalingStart2) * (player.galaxies - galaxyCostScalingStart2+1) * 4 * scalingspd
    }

    if (player.galaxies >= galaxyCostScalingStart3) { // remote
		let scaling=(player.galaxies-galaxyCostScalingStart3+1);
		if(player.challenges.includes("postcngm4r_4"))scaling*=0.9;
		if(player.timeless.upgrades.includes(16))scaling*=0.8;
		scaling *= scalingspd;
        amount = Math.floor(amount * Math.pow(1.05, scaling))
    }
	
    if (player.infinityUpgrades.includes("resetBoost")) amount -= 9;
    if (player.challenges.includes("postc7")) amount -= 11;

    return Math.ceil(amount);
}

function getETA(cost) {
    var a = 100;
    if (player.money.gte(cost)) return 0
    while (ETACalc(a).lt(cost)) {
        a *= 10;
        if (a > 1e20) return Infinity;
    }
    var b = a / 10;
    var q = ETACalc((a+b)/2);
    while (q.gt(cost.times(1.0001)) || q.lt(cost.dividedBy(1.0001))) {
        console.log("q = "+q)
        console.log("a = "+a)
        console.log("b = "+b)
        if (q.lt(cost)) a = (a+b)/2;
        else b = (a+b)/2;
        q = ETACalc((a+b)/2);
    }
    return (a+b)/2;
}

function ETACalc(t) {
    var value = player.money.plus(getDimensionProductionPerSecond(1).times(t));
    var div = 1;
    for (let tier = 2; tier <= 8; ++tier) {
        var name = TIER_NAMES[tier-1]
        div *= tier;
        value = value.plus(getDimensionProductionPerSecond(tier).times(getDimensionProductionPerSecond(tier-1)).times(Decimal.pow(t,tier)).dividedBy(Decimal.max(player[name+"Amount"].times(div).times(10), 1))) ;
    }
    return value
}



var worstChallengeTime = 1

function updateWorstChallengeTime() {
    worstChallengeTime = 1
    for (var i=0; i<13; i++) {
        if (player.challengeTimes[i] > worstChallengeTime) worstChallengeTime = player.challengeTimes[i]
    }
}


function sacrificeConf() {
    player.options.sacrificeConfirmation = !player.options.sacrificeConfirmation
}

function gSacrificeConf() {
    player.options.gSacrificeConfirmation = !player.options.gSacrificeConfirmation
}

function changeToDilation(x, dilationstart){
    if (x.lte(0)) return 0
    if(x.log10()>=dilationstart){
	  x = Decimal.pow(10, Math.pow(x.log10()/dilationstart, getDilationPower())*dilationstart)
    }
	return x;
}


function updateDimensions() {
    if (document.getElementById("antimatterdimensions").style.display == "block" && document.getElementById("dimensions").style.display == "block") {

        for (let tier = 1; tier <= 8; ++tier) {
            var name = TIER_NAMES[tier];
            if (!canBuyDimension(tier) && document.getElementById(name + "Row").style.display !== "table-row") {
                break;
            }
            document.getElementById(name + "D").childNodes[0].nodeValue = DISPLAY_NAMES[tier] + " Dimension x" + formatValue(player.options.notation, getDimensionFinalMultiplier(tier), 1, 1);
            document.getElementById(name + "Amount").textContent = getDimensionDescription(tier);
        }



        for (let tier = 1; tier <= 8; ++tier) {
            var name = TIER_NAMES[tier];
            if (!canBuyDimension(tier)) {
                break;
            }

            document.getElementById(name + "Row").style.display = "table-row";
            document.getElementById(name + "Row").style.visibility = "visible";


        }

        var shiftRequirement = getShiftRequirement(0);
        var timeShiftRequirement = getTimeShiftRequirement(0);
        var tickspeedShiftRequirement = getTickspeedShiftRequirement(0);
        if (player.currentChallenge == "challenge4" ? shiftRequirement.tier < 6 : shiftRequirement.tier < 8) {
            document.getElementById("resetLabel").textContent = 'Dimension Shift ('+ player.resets +'): requires ' + shiftRequirement.amount + " " + DISPLAY_NAMES[shiftRequirement.tier] + " Dimensions"
        }
        else document.getElementById("resetLabel").textContent = 'Dimension Boost ('+ player.resets +'): requires ' + shiftRequirement.amount + " " + DISPLAY_NAMES[shiftRequirement.tier] + " Dimensions"

        if (player.tdBoosts < 7) {
            document.getElementById("timeBoostLabel").textContent = 'Time Dimension Shift ('+ player.tdBoosts +'): requires ' + timeShiftRequirement.amount + " " + DISPLAY_NAMES[timeShiftRequirement.tier] + " Time Dimensions"
        }
        else document.getElementById("timeBoostLabel").textContent = 'Time Dimension Boost ('+ player.tdBoosts +'): requires ' + timeShiftRequirement.amount + " " + DISPLAY_NAMES[timeShiftRequirement.tier] + " Time Dimensions"

        document.getElementById("tickspeedResetLabel").textContent = tickspeedShiftRequirement.prefix + 'Tickspeed Boost ('+ player.tickspeedBoosts +'): requires ' + tickspeedShiftRequirement.amount + " " + DISPLAY_NAMES[tickspeedShiftRequirement.tier] + " Dimensions"

        if (player.currentChallenge == "challenge4" ? player.resets > 2 : player.resets > 3) {
            document.getElementById("softReset").textContent = "Reset the game for a Boost"
        } else {
            document.getElementById("softReset").textContent = "Reset the game for a new Dimension"
        }
        if (player.tdBoosts >= 7) {
            document.getElementById("timeSoftReset").textContent = "Reset the game for a Boost"
        } else {
            document.getElementById("timeSoftReset").textContent = "Reset the game for a new Dimension"
        }
        let extraGals = player.replicanti.galaxies
        if (player.timestudy.studies.includes(225)) extraGals += Math.floor(player.replicanti.amount.e / 1000)
        if (player.timestudy.studies.includes(226)) extraGals += Math.floor(player.replicanti.gal / 15)
        var galString = ""
        if (player.galaxies >= Infinity) galString += "Cosmic Galaxies (";
        else if (player.galaxies >= Infinity) galString += "Etheral Galaxies (";
        else if (player.galaxies >= getGalaxyCostScalingStart5()) galString += "Ghostly Galaxies (";
        else if (player.galaxies >= getGalaxyCostScalingStart4()) galString += "Dark Matter Galaxies (";
        else if (player.galaxies >= getGalaxyCostScalingStart3()) galString += "Remote Antimatter Galaxies (";
        else if (player.galaxies >= getGalaxyCostScalingStart2()) galString += "Further Antimatter Galaxies (";
        else if (player.galaxies >= getGalaxyCostScalingStart()) galString += "Distant Antimatter Galaxies (";
        else galString += "Antimatter Galaxies (";
        galString += player.galaxies;
        if (extraGals > 0) galString += " + "+extraGals;
        if (player.dilation.freeGalaxies > 0) galString += " + "+player.dilation.freeGalaxies;
        galString += "): requires " + getGalaxyRequirement()
        if (player.currentChallenge == "challenge4") galString +=  " Sixth Dimensions";
        else galString +=  " Eighth Dimensions";
        document.getElementById("secondResetLabel").textContent = galString;
    }

    if (canSeeTickSpeed()) {
        var tickmult = getTickSpeedMultiplier()
        if (tickmult < 1e-9) document.getElementById("tickLabel").textContent = "Divide tickspeed by " + shortenDimensions(1 / tickmult)
        else {
            var places = 2
            if (tickmult < 0.2) places = Math.max(2,Math.floor(Math.log10(Math.round(1/tickmult))))
            document.getElementById("tickLabel").textContent = 'Reduce tickspeed by ' + ((1 - tickmult) * 100).toFixed(places) + '%'
        }

        document.getElementById("tickLabel").textContent += ' and get ' + formatValue(player.options.notation, getPostC3RewardMult(), 3, 3) + 'x to all dims';

        document.getElementById("tickSpeed").style.visibility = "visible";
        document.getElementById("tickSpeedMax").style.visibility = "visible";
        document.getElementById("tickLabel").style.visibility = "visible";
        document.getElementById("tickSpeedAmount").style.visibility = "visible";
        if (player.currentChallenge === 'challenge14') {
            document.getElementById("tickSpeedPurchases").style.visibility = "visible";
        } else {
            document.getElementById("tickSpeedPurchases").style.visibility = "hidden";
        }
    } else {
        document.getElementById("tickSpeed").style.visibility = "hidden";
        document.getElementById("tickSpeedMax").style.visibility = "hidden";
        document.getElementById("tickLabel").style.visibility = "hidden";
        document.getElementById("tickSpeedAmount").style.visibility = "hidden";
        document.getElementById("tickSpeedPurchases").style.visibility = "hidden";
    }

    if (player.bestInfinityTime == 9999999999) {
        document.getElementById("bestInfinity").textContent = ""
        document.getElementById("infinitied").textContent = ""
        document.getElementById("thisInfinity").textContent = ""
    } else {
        document.getElementById("bestInfinity").textContent = "Your fastest Infinity is in " + timeDisplay(player.bestInfinityTime) + "."
        document.getElementById("thisInfinity").textContent = "You have spent " + timeDisplay(player.thisInfinityTime) + " in this Infinity."
        if (player.infinityPoints.equals(1)) {
            document.getElementById("infinityPoints1").textContent = "You have 1 Infinity point."
            document.getElementById("infinityPoints2").textContent = "You have 1 Infinity point."
        }
        else {
            document.getElementById("infinityPoints1").innerHTML = "You have <span class=\"IPAmount1\">"+shortenDimensions(player.infinityPoints)+"</span> Infinity points."
            document.getElementById("infinityPoints2").innerHTML = "You have <span class=\"IPAmount2\">"+shortenDimensions(player.infinityPoints)+"</span> Infinity points."
        }
        if (player.infinitied == 1) document.getElementById("infinitied").textContent = "You have infinitied 1 time."
        else document.getElementById("infinitied").textContent = "You have infinitied " + player.infinitied.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",") + " times."
        if (player.infinitiedBank > 0) document.getElementById("infinitied").textContent = "You have infinitied " + player.infinitied.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",") + " times this eternity."

    }

    if (GSUnlocked()) {
        document.getElementById("galaxybtn").style.display = "inline-block"
        if (player.galacticSacrifice.galaxyPoints.eq(1)) {
            document.getElementById("galaxyPoints").textContent = "You have 1 Galaxy point."
            document.getElementById("galaxyPoints2").innerHTML = "You have <span class=\"GPAmount\">1</span> Galaxy point."
        } else {
            document.getElementById("galaxyPoints").innerHTML = "You have "+shortenDimensions(new Decimal(player.galacticSacrifice.galaxyPoints))+" Galaxy points."
            document.getElementById("galaxyPoints2").innerHTML = "You have <span class=\"GPAmount\">"+shortenDimensions(new Decimal(player.galacticSacrifice.galaxyPoints))+"</span> Galaxy points."
        }
    } else {
        document.getElementById("galaxybtn").style.display = "none"
		document.getElementById("galaxyPoints2").innerHTML = ""
    }

    if (document.getElementById("stats").style.display == "block" && document.getElementById("statistics").style.display == "block") {
        document.getElementById("totalmoney").textContent = 'You have made a total of ' + shortenMoney(player.totalmoney) + ' antimatter.'
        document.getElementById("totalresets").textContent = 'You have done ' + player.resets + ' dimensional boosts/shifts.'
        document.getElementById("galaxies").textContent = 'You have ' + Math.round(player.galaxies) + ' Antimatter Galaxies.'
        document.getElementById("totalTime").textContent = "You have played for " + timeDisplay(player.totalTimePlayed) + "."

        if (player.eternities == 0) {
            document.getElementById("eternitied").textContent = ""
            document.getElementById("besteternity").textContent = ""
            document.getElementById("thiseternity").textContent = ""
        } else {
            document.getElementById("eternitied").textContent = "You have Eternitied " + player.eternities.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",") + " times."
            document.getElementById("besteternity").textContent = "You have spent "+timeDisplay(player.thisEternity)+" in this Eternity."
            document.getElementById("thiseternity").textContent = "Your fastest Eternity is in "+timeDisplay(player.bestEternity)+"."
        }
    }

    if (document.getElementById("infinity").style.display == "block") {
        if (document.getElementById("preinf").style.display == "block") {
            document.getElementById("infi11").innerHTML = "Normal dimensions gain a multiplier and all dilation effects starts later based on time played.<br>Currently: " + formatValue(player.options.notation, timeMultNum, 2, 2) + "x<br>Cost: 1 IP"
            document.getElementById("infi12").innerHTML = "First and Eighth Dimensions gain a multiplier based on infinitied stat and unlock a Galaxy Upgrade<br>Currently: " + formatValue(player.options.notation, dimMults(), 1, 1) + "x<br>Cost: 1 IP"
            document.getElementById("infi13").innerHTML = "Third and Sixth Dimensions gain a multiplier based on infinitied stat and unlock a Galaxy Upgrade<br>Currently: " + formatValue(player.options.notation, dimMults(), 1, 1) + "x<br>Cost: 1 IP"
            document.getElementById("infi21").innerHTML = "Increase the multiplier for buying 10 Dimensions and unlock a Galaxy Upgrade<br>2x -> " + infUpg12Pow().toFixed(3) + "x<br>Cost: 1 IP"
            document.getElementById("infi22").innerHTML = "Second and Seventh Dimensions gain a multiplier based on infinitied stat and unlock a Galaxy Upgrade<br>Currently: " + formatValue(player.options.notation, dimMults(), 1, 1) + "x<br>Cost: 1 IP"
            document.getElementById("infi23").innerHTML = "Fourth and Fifth Dimensions gain a multiplier based on infinitied stat and unlock a Galaxy Upgrade<br>Currently: " + formatValue(player.options.notation, dimMults(), 1, 1) + "x<br>Cost: 1 IP"
            document.getElementById("infi31").innerHTML = "Normal dimensions gain a multiplier and all dilation effects starts later based on time spent in current infinity<br>Currently: " + formatValue(player.options.notation, timeMultNum2, 2, 2) + "x<br>Cost: 3 IP"
            document.getElementById("infi32").innerHTML = "Multiplier for unspent Infinity Points on 1st Dimension<br>Currently: " + formatValue(player.options.notation, getUnspentIPBonus(), 2, 2) + "x<br>Cost: 5 IP"
            document.getElementById("infi33").innerHTML = "Dimension boosts are stronger<br>Currently: " + formatValue(player.options.notation, getResetMult(), 2, 2) + "x<br>Cost: 7 IP"
            document.getElementById("infi34").innerHTML = "Infinity Point generation based on fastest infinity <br>Currently: "+shortenDimensions(getIPMult())+" every " + timeDisplay(player.bestInfinityTime*10) + "<br>Cost: 10 IP"
        } else if (document.getElementById("postinf").style.display == "block") {
            document.getElementById("postinfi01").innerHTML = "Multiplier to galaxy points based on infinities<br>Currently: "+formatValue(player.options.notation, getPost01Mult(), 2, 2)+"x<br>Cost: "+shortenCosts(1e3)+" IP"
            document.getElementById("postinfi02").innerHTML = "Decrease dimension boost cost increase by 1<br>Currently: "+ getDimboostCostIncrease() + ' -> ' + (getDimboostCostIncrease() - 1)+"<br>Cost: "+shortenCosts(2e4)+" IP"
            if (player.infinityUpgrades.includes("dimboostCost")) document.getElementById("postinfi02").innerHTML = "Decrease dimension boost cost increase by 1<br>Currently: "+ getDimboostCostIncrease()+"<br>Cost: "+shortenCosts(2e4)+" IP"
            document.getElementById("postinfi03").innerHTML = "Decrease galaxy cost increase by 5<br>Currently: " + getGalaxyCostIncrease().toFixed(2) + ' -> ' + (getGalaxyCostIncrease() - 5).toFixed(2) + "<br>Cost: "+shortenCosts(5e5)+" IP"
            if (player.infinityUpgrades.includes("galCost")) document.getElementById("postinfi03").innerHTML = "Decrease galaxy cost increase by 5<br>Currently: " + getGalaxyCostIncrease().toFixed(2) + "<br>Cost: "+shortenCosts(5e5)+" IP"
            document.getElementById("postinfi04").innerHTML = "Dimension multipliers are further increased by g31 <br>x^" + galUpgrade31().toFixed(2) + ' -> ' + (galUpgrade31() + .02).toFixed(2) + '</br> Cost: ' + formatValue(player.options.notation, player.dimPowerIncreaseCost, 2, 2) + ' IP';
            if (player.extraDimPowerIncrease >= 50) document.getElementById("postinfi04").innerHTML = "Dimension multipliers are further increased by g31 <br>x^" + galUpgrade31().toFixed(2);
            document.getElementById("postinfi11").innerHTML = "Power up all dimensions based on total antimatter produced<br>Currently: "+ formatValue(player.options.notation, totalMult, 2, 2)+"x<br>Cost: "+shortenCosts(1e4)+" IP"
            document.getElementById("postinfi21").innerHTML = "Power up all dimensions based on current antimatter<br>Currently: "+ formatValue(player.options.notation, currentMult, 2, 2)+"x<br>Cost: "+shortenCosts(5e4)+" IP"
            document.getElementById("postinfi31").innerHTML = "Tickspeed cost multiplier increase <br>"+getTickSpeedCostMultiplierIncrease().toFixed(2)+"x -> "+getTickSpeedCostMultiplierIncrease(-1).toFixed(2)+"x<br>Cost: "+formatValue(player.options.notation, player.tickSpeedMultDecreaseCost, 2, 2) +" IP"
            if (player.tickSpeedMultDecrease <= 2) document.getElementById("postinfi31").innerHTML = "Tickspeed cost multiplier increase <br>"+getTickSpeedCostMultiplierIncrease().toFixed(2)+"x"
            document.getElementById("postinfi22").innerHTML = "Power up all dimensions based on achievements completed <br>Currently: "+formatValue(player.options.notation, achievementMult, 2, 2)+"x<br>Cost: "+shortenCosts(1e6)+" IP"
            document.getElementById("postinfi12").innerHTML = "Power up all dimensions based on amount infinitied <br>Currently: "+formatValue(player.options.notation, infinitiedMult, 2, 2)+"x<br>Cost: "+shortenCosts(1e5)+" IP"
            document.getElementById("postinfi41").innerHTML = "Makes galaxies 70% stronger <br>Cost: "+shortenCosts(5e11)+" IP"
            document.getElementById("postinfi32").innerHTML = "Power up all dimensions based on slowest challenge run<br>Currently: "+formatValue(player.options.notation, challengeMult, 2, 2)+"x<br>Cost: "+shortenCosts(1e7)+" IP"
            document.getElementById("postinfi42").innerHTML = "Dimension cost multiplier increase <br>"+getDimensionCostMultiplierIncrease().toFixed(2)+"x -> "+getDimensionCostMultiplierIncrease(-1).toFixed(2)+"x<br>Cost: "+formatValue(player.options.notation, player.dimensionMultDecreaseCost, 2, 2) +" IP"
            document.getElementById("postinfi50").innerHTML = "Decrease dimboost cost increase by 1 <br>"+ getDimboostCostIncrease()+ " -> " + (getDimboostCostIncrease()-1)+ "<br> Cost: " +shortenCosts(1e22) + " IP"
	          if (player.infinityUpgrades.includes("postinfi50")) document.getElementById("postinfi50").innerHTML = "Deacrease dimboost cost increase by 1<br> Currently: " + getDimboostCostIncrease() + "<br> Cost: " + shortenCosts(1e22) + " IP"
            document.getElementById("postinfi51").innerHTML = "Galaxies are 40% more effective <br> Cost: " +shortenCosts(1e26) + " IP"
            document.getElementById("postinfi52").innerHTML = "Decrease galaxy cost increase by 3 <br>"+ getGalaxyCostIncrease().toFixed(2)+ " -> " + (getGalaxyCostIncrease()-3).toFixed(2)+ "<br> Cost: " +shortenCosts(1e22) + " IP"
	          if (player.infinityUpgrades.includes("postinfi52"))document.getElementById("postinfi52").innerHTML =  "Decrease galaxy cost increase by 3 <br>Currently: "+ getGalaxyCostIncrease().toFixed(2)+ "<br> Cost: " +shortenCosts(1e22) + " IP"
            document.getElementById("postinfi53").innerHTML = "Divide ID cost increases by 50 <br> Cost: " +shortenCosts(1e32) + " IP"
            document.getElementById("postinfi13").innerHTML = "You passively generate Infinitied stat based on your fastest infinity.<br>1 Infinity every "+timeDisplay(player.bestInfinityTime*5)+ " <br>Cost: "+shortenCosts(20e6)+" IP"
            document.getElementById("postinfi23").innerHTML = (player.achievements.includes("r28")?"Dimension Boost Autobuyer can buy max Dimension Boosts":"Dimension Boost Autobuyer can bulk buy Dimension Boosts")+" <br>Cost: "+shortenCosts(5e6)+" IP"
            document.getElementById("postinfi33").innerHTML = "Autobuyers work twice as fast <br>Cost:"+shortenCosts(1e15)+" IP"
            if (player.dimensionMultDecrease <= 3) document.getElementById("postinfi42").innerHTML = "Dimension cost multiplier increase <br>"+getDimensionCostMultiplierIncrease().toFixed(2)+"x"
            document.getElementById("offlineProd").innerHTML = "Generates "+player.offlineProd+"% > "+Math.max(Math.max(5, player.offlineProd + 5), Math.min(50, player.offlineProd + 5))+"% of your best IP/min from last 10 infinities, works offline<br>Currently: "+shortenMoney(bestRunIppm.times(player.offlineProd/100)) +"IP/min<br> Cost: "+
            formatValue(player.options.notation, player.offlineProdCost, 2, 2)+" IP";
            if (player.offlineProd == 50) document.getElementById("offlineProd").innerHTML = "Generates "+player.offlineProd+"% of your best IP/min from last 10 infinities, works offline<br>Currently: "+shortenMoney(bestRunIppm.times(player.offlineProd/100)) +" IP/min"

			      document.getElementById("postinfir5").style.display = (player.infinityDimension3.amount.gt(0)||player.eternities > 0)?"":"none"

            document.getElementById("postinfi60").innerHTML = "You gain more IP based on galaxies<br>(2^galaxies) <br>Currently: "+formatValue(player.options.notation,getB60Mult(),2,0)+"x <br>Cost: "+formatValue(player.options.notation,1e50,0,0)+" IP"
            if (player.infinityUpgrades.includes("postinfi70"))document.getElementById("postinfi60").innerHTML = "You gain more IP based on galaxies<br>(2.2^galaxies) <br>Currently: "+formatValue(player.options.notation,getB60Mult(),2,0)+"x <br>Cost: "+formatValue(player.options.notation,1e50,0,0)+" IP"
			if (player.achievements.includes("r96"))document.getElementById("postinfi60").innerHTML = "You gain more IP based on galaxies<br>(2.5^galaxies) <br>Currently: "+formatValue(player.options.notation,getB60Mult(),2,0)+"x <br>Cost: "+formatValue(player.options.notation,1e50,0,0)+" IP"
			if (player.achievements.includes("r96")&&player.infinityUpgrades.includes("postinfi70"))document.getElementById("postinfi60").innerHTML = "You gain more IP based on galaxies<br>(2.8^galaxies) <br>Currently: "+formatValue(player.options.notation,getB60Mult(),2,0)+"x <br>Cost: "+formatValue(player.options.notation,1e50,0,0)+" IP"
			
			document.getElementById("postinfir6").style.display = (player.infinityDimension4.amount.gt(0)||player.eternities > 0)?"":"none"
	          document.getElementById("postinfi61").innerHTML = "Make g11 better <br> Cost: " + formatValue(player.options.notation,1e69,0,0) + " IP"
            document.getElementById("postinfi62").innerHTML = "Make g13 better based on dimboosts <br> Cost: " + formatValue(player.options.notation,1e170, 2,0) + " IP"
            document.getElementById("postinfi63").innerHTML = "Unlock a new row of galaxy upgrades <br> Cost: " + formatValue(player.options.notation,1e80, 2,0) + " IP"
			
			document.getElementById("postinfir7").style.display = (player.achievements.includes("r85"))?"":"none"
			document.getElementById("postinfi70").innerHTML = "Increase the base of upgrade above to 2.2<br>Cost: "+formatValue(player.options.notation,1e160,0,0)+" IP"
	        if (player.achievements.includes("r96"))document.getElementById("postinfi70").innerHTML = "Increase the base of upgrade above to 2.8<br>Cost: "+formatValue(player.options.notation,1e160,0,0)+" IP"
			document.getElementById("postinfi71").innerHTML = "GP boost itself<br>Currently: "+shortenDimensions(player.galacticSacrifice.galaxyPoints.add(1).pow(0.2))+"x<br> Cost: " + formatValue(player.options.notation,1e180,0,0) + " IP"
            document.getElementById("postinfi72").innerHTML = "The multiplier for buying Infinity Dimensions are "+shortenDimensions(Number.MAX_VALUE**0.2)+"<br> Cost: " + formatValue(player.options.notation,1e200, 2,0) + " IP"
            if (player.galacticSacrifice.upgrades.includes(65))document.getElementById("postinfi72").innerHTML = "The multiplier for buying Infinity Dimensions are "+shortenDimensions(Number.MAX_VALUE)+"<br> Cost: " + formatValue(player.options.notation,1e200, 2,0) + " IP"
            document.getElementById("postinfi73").innerHTML = "Dimensional Sacrifice is stronger and applied to 8th dimension post-dilation. Dimensional Sacrifice affects second dilation threshold at a reduced rate.<br> Cost: " + formatValue(player.options.notation,1e215, 2,0) + " IP"
			
	        
        }
    }

    document.getElementById("newgalrow1").style.display = (player.eternities>0 || player.challenges.includes("postc1"))?"":"none"
    document.getElementById("newgalrow2").style.display = (player.eternities>6 || player.infinityUpgrades.includes("postinfi63"))?"":"none"
    document.getElementById("newgalrow3").style.display = (player.eternities>0)?"":"none"
    document.getElementById("newgalrow4").style.display = (player.timeless.upgrades.includes(28))?"":"none"
    document.getElementById("newgalrow5").style.display = (player.achievements.includes("ngm4r5"))?"":"none"

    galacticUpgradeSpanDisplay();

    if (document.getElementById("eternityupgrades").style.display == "block" && document.getElementById("eternitystore").style.display == "block") {
        document.getElementById("eter1").innerHTML = "Infinity Dimensions multiplier based on unspent EP (x+1)<br>Currently: "+shortenMoney(player.eternityPoints.plus(1))+"x<br>Cost: 5 EP"
        document.getElementById("eter2").innerHTML = "Infinity Dimension multiplier based on eternities<br>Currently: "+shortenMoney(Decimal.pow(Math.min(player.eternities, 100000)/200 + 1, Math.log(Math.min(player.eternities, 100000)*2+1)/Math.log(4)).times(new Decimal((player.eternities-100000)/200 + 1).times(Math.log((player.eternities- 100000)*2+1)/Math.log(4)).max(1)))+"x<br>Cost: 10 EP"
        document.getElementById("eter3").innerHTML = "Infinity Dimensions multiplier based on sum of Infinity Challenge times<br>Currently: "+shortenMoney(Decimal.pow(2,300/Math.max(infchallengeTimes, player.achievements.includes("r112") ? 6.1 : 7.5)))+"x<br>Cost: "+shortenCosts(50e3)+" EP"
        document.getElementById("eter4").innerHTML = "Your achievement bonus affects Time Dimensions (post-dilation)"+"<br>Cost: "+shortenCosts(1e16)+" EP"
        document.getElementById("eter5").innerHTML = "Time Dimensions are multiplied by your unspent time theorems (post-dilation)"+"<br>Cost: "+shortenCosts(1e40)+" EP"
        document.getElementById("eter6").innerHTML = "Time Dimensions are multiplied by days played (post-dilation)"+"<br>Cost: "+shortenCosts(1e50)+" EP"
        document.getElementById("eter7").innerHTML = "Unlock Timeless<br>Req: 100 Eternities<br>Cost: "+shortenCosts(1e25)+" EP"
		document.getElementById("eter8").innerHTML = "The second row of Eternity Upgrades boost EP gain (post-dilation)<br>Currently: "+shortenMoney(EU8Effect())+"x<br>Cost: "+shortenCosts(1e60)+" EP"
    }

    if (document.getElementById("timeless").style.display == "block") {
        if (player.timeless.active) {
            document.getElementById("entertimeless").textContent = "Exit Timeless for "+shortenDimensions(gainedTimelessShards())+" Timeless Shards. Next Timeless Shard at "+shortenDimensions(nextTimelessShardAt())+" Timeshards.";
			if (player.timeless.upgrades.includes(32))document.getElementById("entertimeless").textContent = "Exit Timeless. Reach "+shortenDimensions(nextTimelessShardAt())+" Timeshards to get more Timeless shards.";
        }
        else document.getElementById("entertimeless").textContent = "Enter Timeless."
    }

    if (document.getElementById("dilation").style.display == "block") {
        if (player.dilation.active) {
            if (Math.pow(Decimal.log10(player.money) / 400, 1.5) * (Math.pow(3, player.dilation.rebuyables[3])) - player.dilation.totalTachyonParticles <= 0) {
                document.getElementById("enabledilation").innerHTML = "Disable dilation.<br>Reach " + shortenMoney(Decimal.pow(10, Math.pow(player.dilation.tachyonParticles * Math.pow(400, 1.5) / Math.pow(3, player.dilation.rebuyables[3]), 2/3))) + " antimatter to gain more Tachyon Particles."
            } else {
                document.getElementById("enabledilation").textContent = "Disable dilation."
            }
        }
        else document.getElementById("enabledilation").textContent = "Dilate time."
    }
}

function updateCosts() {
    document.getElementById("first").textContent = 'Cost: ' + shortenCosts(player.firstCost);
    document.getElementById("second").textContent = 'Cost: ' + shortenCosts(player.secondCost);
    document.getElementById("third").textContent = 'Cost: ' + shortenCosts(player.thirdCost);
    document.getElementById("fourth").textContent = 'Cost: ' + shortenCosts(player.fourthCost);
    document.getElementById("fifth").textContent = 'Cost: ' + shortenCosts(player.fifthCost);
    document.getElementById("sixth").textContent = 'Cost: ' + shortenCosts(player.sixthCost);
    document.getElementById("seventh").textContent = 'Cost: ' + shortenCosts(player.seventhCost);
    document.getElementById("eight").textContent = 'Cost: ' + shortenCosts(player.eightCost);

    document.getElementById("firstMax").textContent = 'Until 10, Cost: ' + shortenCosts(player.firstCost.times(10 - dimBought(1)));
    document.getElementById("secondMax").textContent = 'Until 10, Cost: ' + shortenCosts(player.secondCost.times(10 - dimBought(2)));
    document.getElementById("thirdMax").textContent = 'Until 10, Cost: ' + shortenCosts(player.thirdCost.times(10 - dimBought(3)));
    document.getElementById("fourthMax").textContent = 'Until 10, Cost: ' + shortenCosts(player.fourthCost.times(10 - dimBought(4)));
    document.getElementById("fifthMax").textContent = 'Until 10, Cost: ' + shortenCosts(player.fifthCost.times(10 - dimBought(5)));
    document.getElementById("sixthMax").textContent = 'Until 10, Cost: ' + shortenCosts(player.sixthCost.times(10 - dimBought(6)));
    document.getElementById("seventhMax").textContent = 'Until 10, Cost: ' + shortenCosts(player.seventhCost.times(10 - dimBought(7)));
    document.getElementById("eightMax").textContent = 'Until 10, Cost: ' + shortenCosts(player.eightCost.times(10 - dimBought(8)));

    document.getElementById("tickSpeed").textContent = 'Cost: ' + shortenCosts(player.tickSpeedCost);


    for (var i=1; i<=8; i++) {

        document.getElementById("infMax"+i).textContent = "Cost: " + shortenCosts(player["infinityDimension"+i].cost) + " IP"
    }

    for (var i=1; i<=8; i++) {

        document.getElementById("timeMax"+i).textContent = "Cost: " + shortenDimensions(player["timeDimension"+i].cost) + " EP"
    }

    for (var i=1; i<=8; i++) {
		var dim = player["timeDimension"+i]
		dim.costAntimatter = Decimal.pow(timeDimCostMultsAntimatter[i], dim.boughtAntimatter).times(timeDimStartCostsAntimatter[i])
  if (dim.costAntimatter.gte(Number.MAX_VALUE)) {
      dim.costAntimatter = Decimal.pow(timeDimCostMultsAntimatter[i]*1.5, dim.boughtAntimatter).times(timeDimStartCostsAntimatter[i])
  }
  if (dim.costAntimatter.gte("1e5000")) {
      dim.costAntimatter = Decimal.pow(timeDimCostMultsAntimatter[i]*2, dim.boughtAntimatter).times(timeDimStartCostsAntimatter[i])
  }
  if (dim.costAntimatter.gte("1e50000")) {
      dim.costAntimatter = Decimal.pow(timeDimCostMultsAntimatter[i]*getTDFinalScaling(i,dim.boughtAntimatter), dim.boughtAntimatter).times(timeDimStartCostsAntimatter[i])
  }
  if (player.currentChallenge == "postcngm3_1"){
	  dim.costAntimatter = Decimal.pow(timeDimCostMultsAntimatter[i], (Math.pow(1.01,dim.boughtAntimatter)-1)*100).times(timeDimStartCostsAntimatter[i]);
	  if(Math.pow(1.01,dim.boughtAntimatter) >= 1e100 || dim.costAntimatter.gte("0.99e9000000000000000"))dim.costAntimatter=new Decimal("0.99e9000000000000000");
  }
  if (player.galacticSacrifice.upgrades.includes(11) && !player.galacticSacrifice.upgrades.includes(81)) dim.costAntimatter =  dim.costAntimatter.div(galUpgrade11())
  if (player.galacticSacrifice.upgrades.includes(63)) dim.costAntimatter =  dim.costAntimatter.div(galUpgrade63())
        document.getElementById("timeMax"+i+"Antimatter").textContent = "Cost: " + shortenDimensions(player["timeDimension"+i].costAntimatter)
    }
}

function floatText(id, text, leftOffset = 150) {
    if (!player.options.animations.floatingText) return
    var el = $("#"+id)
    el.append("<div class='floatingText' style='left: "+leftOffset+"px'>"+text+"</div>")
    setTimeout(function() {
        el.children()[0].remove()
    }, 1000)
}




function isEterChall(elem) {
    return !elem.id.includes("eter")
}

function updateChallenges() {
    try {
        var buttons = Array.from(document.getElementsByClassName('onchallengebtn')).filter(isEterChall)
        for (var i=0; i < buttons.length; i++) {
            buttons[i].className = "challengesbtn";
            buttons[i].textContent = "Start"
        }

        var buttonss = Array.from(document.getElementsByClassName('completedchallengesbtn')).filter(isEterChall)
        for (var i=0; i < buttonss.length; i++) {
            buttonss[i].className = "challengesbtn";
            buttonss[i].textContent = "Start"
        }


        for (var i=0; i < player.challenges.length; i++) {
            document.getElementById(player.challenges[i]).className = "completedchallengesbtn";
            document.getElementById(player.challenges[i]).textContent = "Completed"
        }

        if (player.currentChallenge != "") {
            document.getElementById(player.currentChallenge).className = "onchallengebtn"
            document.getElementById(player.currentChallenge).textContent = "Running"
        }

        if (player.break || Object.keys(player.eternityChalls).length > 0 || player.eternityChallUnlocked !== 0) document.getElementById("challTabButtons").style.display = "table"
        for (var i=1; i<11; i++) {
            if (player.postChallUnlocked >= i) document.getElementById("postc"+i+"div").style.display = "inline-block"
            else document.getElementById("postc"+i+"div").style.display = "none"
        }



    } catch (err) {
        console.log(err)
        updateChallenges()

    }

}


function updateEternityChallenges() {

    for (var property in player.eternityChalls) {
        document.getElementById(property+"div").style.display = "inline-block"
        if (player.eternityChalls[property] < 5) {
            document.getElementById(property).textContent = "Locked"
            document.getElementById(property).className = "lockedchallengesbtn"
        }
        else {
            document.getElementById(property).textContent = "Completed"
            document.getElementById(property).className = "completedchallengesbtn"
        }
    }

    if (player.eternityChallUnlocked !== 0) {
        document.getElementById("eterc"+player.eternityChallUnlocked).textContent = "Start"
        document.getElementById("eterc"+player.eternityChallUnlocked).className = "challengesbtn"
        document.getElementById("eterctabbtn").style.display = "block"
    } else {
        for (i=1; i<13; i++) {
            if (player.eternityChalls["eterc"+i] !== 5) {
                document.getElementById("eterc"+i).textContent = "Locked"
                document.getElementById("eterc"+i).className = "lockedchallengesbtn"
            }
        }
    }

    if (player.eternityChallUnlocked == 0 && player.eternityChalls.eterc1 === undefined) {
        document.getElementById("eterctabbtn").style.display = "none"
        for (i=1; i<13; i++) {
            document.getElementById("eterc"+i+"div").style.display = "none"
        }
    }

    if (player.eternityChalls.eterc1 !== undefined) document.getElementById("eterctabbtn").style.display = "block"
    if (player.etercreq !== 0) document.getElementById("eterc"+player.etercreq+"div").style.display = "block"

    if (player.currentEternityChall !== "") {
        document.getElementById(player.currentEternityChall).textContent = "Running"
        document.getElementById(player.currentEternityChall).className = "onchallengebtn"
    }
}









function toggleChallengeRetry() {
    if (player.options.retryChallenge) {
        player.options.retryChallenge = false
        document.getElementById("retry").textContent = "Automatically retry challenges OFF"
    } else {
        player.options.retryChallenge = true
        document.getElementById("retry").textContent = "Automatically retry challenges ON"
    }
}

document.getElementById("news").onclick = function () {
    if (document.getElementById("news").textContent === "Click this to unlock a secret achievement.") {
        giveAchievement("Real news")
    }
};

document.getElementById("secretstudy").onclick = function () {
    document.getElementById("secretstudy").style.opacity = "1";
    document.getElementById("secretstudy").style.cursor = "default";
    giveAchievement("Go study in real life instead");
    setTimeout(drawStudyTree, 2000);
};

document.getElementById("The first one's always free").onclick = function () {
    giveAchievement("The first one's always free")
};




function glowText(id) {
  var text = document.getElementById(id);
  text.style.setProperty("-webkit-animation", "glow 1s");
  text.style.setProperty("animation", "glow 1s");
}





document.getElementById("maxall").onclick = function () {
    if (!player.break && player.money.gt(Number.MAX_VALUE)) return false;
    if (player.currentChallenge !== 'challenge14') buyMaxTickSpeed();

    for (var tier=1; tier<9;tier++) {
        var name = TIER_NAMES[tier];
        var cost = player[name + 'Cost'].times(10 - dimBought(tier))
        var multBefore = player[name + 'Pow']
        if (tier >= 3 && (player.currentChallenge == "challenge10" || player.currentChallenge == "postc4")) {
            if (!canBuyDimension(tier)) continue
            if (player[TIER_NAMES[tier-2] + 'Amount'].lt(cost)) continue
                if (canBuyDimension(tier)) {
                    if (cost.lt(player[TIER_NAMES[tier-2]+"Amount"]) && dimBought(tier) != 0) {
                        player[TIER_NAMES[tier-2]+"Amount"] = player[TIER_NAMES[tier-2]+"Amount"].minus(cost)
                        player[name + "Amount"] = Decimal.round(player[name + "Amount"].plus(10 - dimBought(tier)))
                        recordBought(name, 10 - dimBought(tier));
                        player[name + 'Pow']  = player[name + 'Pow'].times(getDimensionPowerMultiplier(tier))
                        player[name + "Cost"] = player[name + "Cost"].times(getDimensionCostMultiplier(tier))
                    }
                    while (player[TIER_NAMES[tier-2]+"Amount"].gt(player[name + "Cost"].times(10))) {
                        player[TIER_NAMES[tier-2]+"Amount"] = player[TIER_NAMES[tier-2]+"Amount"].minus(player[name + "Cost"].times(10))
                        player[name + "Cost"] = player[name + "Cost"].times(getDimensionCostMultiplier(tier))
                        player[name + "Amount"] = Decimal.round(player[name + "Amount"].plus(10))
                        recordBought(name, 10);
                        player[name + "Pow"] = player[name + "Pow"].times(getDimensionPowerMultiplier(tier))
                        if (costIncreaseActive(player[name + 'Cost'])) player.costMultipliers[tier-1] = player.costMultipliers[tier-1].times(player.dimensionMultDecrease)
                    }


                    onBuyDimension(tier);
                }
        } else {
        if (!canBuyDimension(tier)) continue
            if (cost.lt(player.money) && dimBought(tier) != 0) {
                player.money = player.money.minus(cost)
                player[name + "Amount"] = Decimal.round(player[name + "Amount"].plus(10 - dimBought(tier)))
                recordBought(name, 10 - dimBought(tier));
                player[name + 'Pow']  = player[name + 'Pow'].times(getDimensionPowerMultiplier(tier))
                player[name + "Cost"] = player[name + "Cost"].times(getDimensionCostMultiplier(tier))
            }
            if (player.money.lt(player[name + "Cost"].times(10))) continue

            if ((player.dimensionMultDecrease > 3 || player.currentChallenge == "challenge5")) {
                while ((player.money.gte(player[name + "Cost"].times(10)) && player.money.lte(Number.MAX_VALUE)) || (player.money.gte(player[name + "Cost"].times(10)) && player.currentChallenge != "challenge5")) {
                        player.money = player.money.minus(player[name + "Cost"].times(10))
                        if (player.currentChallenge != "challenge5") player[name + "Cost"] = player[name + "Cost"].times(getDimensionCostMultiplier(tier))
                        else multiplySameCosts(player[name + 'Cost'])
                        player[name + "Amount"] = Decimal.round(player[name + "Amount"].plus(10))
                        recordBought(name, 10);
                        player[name + "Pow"] = player[name + "Pow"].times(getDimensionPowerMultiplier(tier))
                        if (costIncreaseActive(player[name + "Cost"])) player.costMultipliers[tier-1] = player.costMultipliers[tier-1].times(player.dimensionMultDecrease)
                        if (player.currentChallenge == "challenge8") clearDimensions(tier-1)
                }
            } else {
                if (!costIncreaseActive(player[name + "Cost"])) {
                    while (player.money.gte(player[name + "Cost"].times(10)) && !costIncreaseActive(player[name + "Cost"])) {
                        player.money = player.money.minus(player[name + "Cost"].times(10))
                        if (player.currentChallenge != "challenge5") player[name + "Cost"] = player[name + "Cost"].times(getDimensionCostMultiplier(tier))
                        else multiplySameCosts(player[name + 'Cost'])
                        player[name + "Amount"] = Decimal.round(player[name + "Amount"].plus(10))
                        recordBought(name, 10);
                        player[name + "Pow"] = player[name + "Pow"].times(getDimensionPowerMultiplier(tier))
                        if (costIncreaseActive(player[name + 'Cost'])) player.costMultipliers[tier-1] = player.costMultipliers[tier-1].times(player.dimensionMultDecrease)
                        if (player.currentChallenge == "challenge8") clearDimensions(tier-1)
                }
                }

                if (costIncreaseActive(player[name + "Cost"])) {
					
                }


        }
        }
        if ((player.currentChallenge == "challenge12" || player.currentChallenge == "postc4" || player.currentChallenge == "postc8") && player.matter.equals(0)) player.matter = new Decimal(1);
        if (player.currentChallenge == "challenge2" || player.currentChallenge == "postc4") player.chall2Pow = 0;
        if (player.currentChallenge == "postc4") clearDimensions(tier-1);
        player.postC6Tier = tier;
        onBuyDimension(tier)
        floatText(name + "D", "x" + shortenMoney(player[name + "Pow"].dividedBy(multBefore)))
    }
}




document.getElementById("challengeconfirmation").onclick = function () {
    if (!player.options.challConf) {
        player.options.challConf = true;
        document.getElementById("challengeconfirmation").textContent = "Challenge confirmation OFF"
    } else {
        player.options.challConf = false;
        document.getElementById("challengeconfirmation").textContent = "Challenge confirmation ON"
    }
}




function buyInfinityUpgrade(name, cost) {
    if (player.infinityPoints.gte(cost) && !player.infinityUpgrades.includes(name)) {
        player.infinityUpgrades.push(name);
        player.infinityPoints = player.infinityPoints.minus(cost);
		if (name == "postinfi53") {
			for (tier=1;tier<9;tier++) {
                let dim = player["infinityDimension"+tier]
                dim.cost = new Decimal(infBaseCost[tier]).times(Decimal.pow(infCostMults[tier]/(player.infinityUpgrades.includes("postinfi53")?50:1), (dim.baseAmount/10)*(ECTimesCompleted("eterc12")?1-ECTimesCompleted("eterc12")*0.008:1)))
            }
            updateInfinityDimensions()
		}
    if (name == "postinfi72") {
      for (n=1;n<9;n++) {
        var dim = player["infinityDimension"+n]
        dim.power = Decimal.pow(getInfBuy10Mult(n), dim.baseAmount/10)
      }
    }
        return true
    } else return false
}

document.getElementById("infiMult").onclick = function() {
    if (player.infinityUpgrades.includes("skipResetGalaxy") && player.infinityUpgrades.includes("passiveGen") && player.infinityUpgrades.includes("galaxyBoost") && player.infinityUpgrades.includes("resetBoost") && player.infinityPoints.gte(player.infMultCost)) {
        player.infinityPoints = player.infinityPoints.minus(player.infMultCost)
        player.infMult = player.infMult.times(getIPMultMultiplier());
        player.autoIP = player.autoIP.times(getIPMultMultiplier());
        player.infMultCost = player.infMultCost.times(10)
        document.getElementById("infiMult").innerHTML = "Multiply infinity points from all sources by "+getIPMultMultiplier().toFixed(2)+" <br>currently: "+shorten(getIPMult()) +"x<br>Cost: "+shortenCosts(player.infMultCost)+" IP"
        if (player.autobuyers[11].priority !== undefined && player.autobuyers[11].priority !== null && player.autoCrunchMode == "amount") player.autobuyers[11].priority = player.autobuyers[11].priority.times(2);
        if (player.autoCrunchMode == "amount") document.getElementById("priority12").value = formatValue("Scientific", player.autobuyers[11].priority, 2, 0);
    }
}


function updateEternityUpgrades() {
    document.getElementById("eter1").className = (player.eternityUpgrades.includes(1)) ? "eternityupbtnbought" : (player.eternityPoints.gte(5)) ? "eternityupbtn" : "eternityupbtnlocked"
    document.getElementById("eter2").className = (player.eternityUpgrades.includes(2)) ? "eternityupbtnbought" : (player.eternityPoints.gte(10)) ? "eternityupbtn" : "eternityupbtnlocked"
    document.getElementById("eter3").className = (player.eternityUpgrades.includes(3)) ? "eternityupbtnbought" : (player.eternityPoints.gte(50e3)) ? "eternityupbtn" : "eternityupbtnlocked"
    document.getElementById("eter4").className = (player.eternityUpgrades.includes(4)) ? "eternityupbtnbought" : (player.eternityPoints.gte(1e16)) ? "eternityupbtn" : "eternityupbtnlocked"
    document.getElementById("eter5").className = (player.eternityUpgrades.includes(5)) ? "eternityupbtnbought" : (player.eternityPoints.gte(1e40)) ? "eternityupbtn" : "eternityupbtnlocked"
    document.getElementById("eter6").className = (player.eternityUpgrades.includes(6)) ? "eternityupbtnbought" : (player.eternityPoints.gte(1e50)) ? "eternityupbtn" : "eternityupbtnlocked"
    document.getElementById("eter7").className = (player.eternityUpgrades.includes(7)) ? "eternityupbtnbought" : (player.eternityPoints.gte(1e25) && player.eternities>=100) ? "eternityupbtn" : "eternityupbtnlocked"
    document.getElementById("eter8").className = (player.eternityUpgrades.includes(8)) ? "eternityupbtnbought" : (player.eternityPoints.gte(1e60)) ? "eternityupbtn" : "eternityupbtnlocked"
}


function buyEternityUpgrade(name, cost) {
	if(name==7){
		if(player.eternities<100)return;
	}
    if (player.eternityPoints.gte(cost) && !player.eternityUpgrades.includes(name)) {
        player.eternityUpgrades.push(name)
        player.eternityPoints = player.eternityPoints.minus(cost)
        updateEternityUpgrades()
    }
}


function buyEPMult() {
    if (player.eternityPoints.gte(player.epmultCost)) {
        player.epmult = player.epmult.times(5)
        player.eternityBuyer.limit = player.eternityBuyer.limit.times(5)
        document.getElementById("priority15").value = formatValue("Scientific", player.eternityBuyer.limit, 2, 0);
        player.eternityPoints = player.eternityPoints.minus(player.epmultCost)
        let count = player.epmult.ln()/Math.log(5)
        if (player.epmultCost.gte(new Decimal("1e4000"))) player.epmultCost = Decimal.pow(1000, count + Math.pow(count-1334, 1.2)).times(500)
        else if (player.epmultCost.gte(new Decimal("1e1300"))) player.epmultCost = Decimal.pow(1000, count).times(500)
        else if (player.epmultCost.gte(Number.MAX_VALUE)) player.epmultCost = Decimal.pow(500, count).times(500)
        else if (player.epmultCost.gte(new Decimal("1e100"))) player.epmultCost = Decimal.pow(100, count).times(500)
        else player.epmultCost = Decimal.pow(50, count).times(500)
        document.getElementById("epmult").innerHTML = "You gain 5 times more EP<p>Currently: "+shortenDimensions(player.epmult)+"x<p>Cost: "+shortenDimensions(player.epmultCost)+" EP"
        updateEternityUpgrades()
    }
}

function buyMaxEPMult() {
    while (player.eternityPoints.gte(player.epmultCost)) {
        buyEPMult()
    }
}





function playerInfinityUpgradesOnEternity() {
    if (player.eternities < 4) player.infinityUpgrades = []
    else if (player.eternities < 20) player.infinityUpgrades = ["timeMult", "dimMult", "timeMult2", "skipReset1", "skipReset2", "unspentBonus", "27Mult", "18Mult", "36Mult", "resetMult", "skipReset3", "passiveGen", "45Mult", "resetBoost", "galaxyBoost", "skipResetGalaxy"]
    else player.infinityUpgrades = player.infinityUpgrades
}



document.getElementById("infi11").onclick = function () {
    buyInfinityUpgrade("timeMult",1);
}

document.getElementById("infi21").onclick = function () {
    buyInfinityUpgrade("dimMult",1);
}

document.getElementById("infi12").onclick = function () {
    if (player.infinityUpgrades.includes("timeMult")) buyInfinityUpgrade("18Mult",1);
}

document.getElementById("infi22").onclick = function () {
    if (player.infinityUpgrades.includes("dimMult")) buyInfinityUpgrade("27Mult",1);
}

document.getElementById("infi13").onclick = function () {
    if (player.infinityUpgrades.includes("18Mult")) buyInfinityUpgrade("36Mult",1);
}
document.getElementById("infi23").onclick = function () {
    if (player.infinityUpgrades.includes("27Mult")) buyInfinityUpgrade("45Mult",1);
}

document.getElementById("infi14").onclick = function () {
    if (player.infinityUpgrades.includes("36Mult")) buyInfinityUpgrade("resetBoost",1);
}

document.getElementById("infi24").onclick = function () {
    if (player.infinityUpgrades.includes("45Mult")) buyInfinityUpgrade("galaxyBoost",2);
}

document.getElementById("infi31").onclick = function() {
    buyInfinityUpgrade("timeMult2",3);
}

document.getElementById("infi32").onclick = function() {
    if (player.infinityUpgrades.includes("timeMult2")) buyInfinityUpgrade("unspentBonus",5);
}

document.getElementById("infi33").onclick = function() {
    if (player.infinityUpgrades.includes("unspentBonus")) buyInfinityUpgrade("resetMult",7);
}

document.getElementById("infi34").onclick = function() {
    if (player.infinityUpgrades.includes("resetMult")) buyInfinityUpgrade("passiveGen",10);
}

document.getElementById("infi41").onclick = function() {
    buyInfinityUpgrade("skipReset1",20);
}

document.getElementById("infi42").onclick = function() {
    if (player.infinityUpgrades.includes("skipReset1")) buyInfinityUpgrade("skipReset2", 40)
}

document.getElementById("infi43").onclick = function() {
    if (player.infinityUpgrades.includes("skipReset2")) buyInfinityUpgrade("skipReset3", 80)
}

document.getElementById("infi44").onclick = function() {
    if (player.infinityUpgrades.includes("skipReset3")) buyInfinityUpgrade("skipResetGalaxy", 500)
}

document.getElementById("postinfi01").onclick = function() {
    buyInfinityUpgrade("galPointMult",1e3);
}

document.getElementById("postinfi02").onclick = function() {
    buyInfinityUpgrade("dimboostCost",2e4);
}

document.getElementById("postinfi03").onclick = function() {
    buyInfinityUpgrade("galCost",5e5);
}

document.getElementById("postinfi04").onclick = function() {
    if (player.infinityPoints.gte(player.dimPowerIncreaseCost) && player.extraDimPowerIncrease < 50) {
        player.infinityPoints = player.infinityPoints.minus(player.dimPowerIncreaseCost)
        player.dimPowerIncreaseCost = new Decimal(1e13).times(Decimal.pow(10,Math.min(player.extraDimPowerIncrease,50)+1));
        player.extraDimPowerIncrease += 1;
        if (player.extraDimPowerIncrease > 50) player.dimPowerIncreaseCost = player.dimPowerIncreaseCost.times(Decimal.pow(Decimal.pow(4,5),player.extraDimPowerIncrease-50))
        document.getElementById("postinfi04").innerHTML = "Dimension multipliers are further increased by g31 <br>x^" + galUpgrade31().toFixed(2) + ' -> ' + (galUpgrade31() + .02).toFixed(2) + '</br> Cost: ' + formatValue(player.options.notation, player.dimPowerIncreaseCost, 2, 2) + ' IP';
        if (player.extraDimPowerIncrease >= 50) document.getElementById("postinfi04").innerHTML = "Dimension multipliers are further increased by g31 <br>x^" + galUpgrade31().toFixed(2);
    }
}

document.getElementById("postinfi11").onclick = function() {
    buyInfinityUpgrade("totalMult",1e4);
}

document.getElementById("postinfi21").onclick = function() {
    buyInfinityUpgrade("currentMult",5e4);
}

document.getElementById("postinfi31").onclick = function() {
    if (player.infinityPoints.gte(player.tickSpeedMultDecreaseCost) && player.tickSpeedMultDecrease > 2) {
        player.infinityPoints = player.infinityPoints.minus(player.tickSpeedMultDecreaseCost)
        player.tickSpeedMultDecreaseCost *= 5
        player.tickSpeedMultDecrease--;
        document.getElementById("postinfi31").innerHTML = "Tickspeed cost multiplier increase <br>"+getTickSpeedCostMultiplierIncrease().toFixed(2)+"x -> "+getTickSpeedCostMultiplierIncrease(-1).toFixed(2)+"x<br>Cost: "+formatValue(player.options.notation, player.tickSpeedMultDecreaseCost, 2, 2) +" IP"
        if (player.tickSpeedMultDecrease <= 2) document.getElementById("postinfi31").innerHTML = "Tickspeed cost multiplier increase <br>"+getTickSpeedCostMultiplierIncrease().toFixed(2)+"x"
    }
}

document.getElementById("postinfi41").onclick = function() {
    buyInfinityUpgrade("postGalaxy",5e11);
}

document.getElementById("postinfi12").onclick = function() {
    buyInfinityUpgrade("infinitiedMult",1e5);
}

document.getElementById("postinfi22").onclick = function() {
    buyInfinityUpgrade("achievementMult",1e6);
}

document.getElementById("postinfi32").onclick = function() {
    buyInfinityUpgrade("challengeMult",1e7);
}

document.getElementById("postinfi13").onclick = function() {
    buyInfinityUpgrade("infinitiedGeneration",2e7);
}

document.getElementById("postinfi23").onclick = function() {
    buyInfinityUpgrade("bulkBoost",5e6);
}

document.getElementById("postinfi33").onclick = function() {
    buyInfinityUpgrade("autoBuyerUpgrade",1e15);
}

document.getElementById("postinfi42").onclick = function() {
    if (player.infinityPoints.gte(player.dimensionMultDecreaseCost) && player.dimensionMultDecrease > 3) {
        player.infinityPoints = player.infinityPoints.minus(player.dimensionMultDecreaseCost)
        player.dimensionMultDecreaseCost *= 5000
        player.dimensionMultDecrease--;
        document.getElementById("postinfi42").innerHTML = "Dimension cost multiplier increase <br>"+getDimensionCostMultiplierIncrease().toFixed(2)+"x -> "+getDimensionCostMultiplierIncrease(-1).toFixed(2)+"x<br>Cost: "+formatValue(player.options.notation, player.dimensionMultDecreaseCost, 2, 2) +" IP"
        if (player.dimensionMultDecrease <= 3) document.getElementById("postinfi42").innerHTML = "Dimension cost multiplier increase <br>"+getDimensionCostMultiplierIncrease().toFixed(2)+"x"
    }
}

document.getElementById("postinfi50").onclick = function() {
    buyInfinityUpgrade("postinfi50",1e22);
}

document.getElementById("postinfi51").onclick = function() {
    buyInfinityUpgrade("postinfi51",1e26);
}

document.getElementById("postinfi52").onclick = function() {
    buyInfinityUpgrade("postinfi52",1e22);
}

document.getElementById("postinfi53").onclick = function() {
    buyInfinityUpgrade("postinfi53",1e32);
}

document.getElementById("postinfi60").onclick = function() {
    buyInfinityUpgrade("postinfi60",1e50);
}

document.getElementById("postinfi61").onclick = function() {
    buyInfinityUpgrade("postinfi61",1e69);
}

document.getElementById("postinfi62").onclick = function() {
    buyInfinityUpgrade("postinfi62",1e170);
}

document.getElementById("postinfi63").onclick = function() {
    buyInfinityUpgrade("postinfi63",1e80);
}

document.getElementById("postinfi70").onclick = function() {
    buyInfinityUpgrade("postinfi70",1e160);
}

document.getElementById("postinfi71").onclick = function() {
    buyInfinityUpgrade("postinfi71",1e180);
}

document.getElementById("postinfi72").onclick = function() {
    buyInfinityUpgrade("postinfi72",1e200);
}

document.getElementById("postinfi73").onclick = function() {
    buyInfinityUpgrade("postinfi73",1e215);
}

document.getElementById("offlineProd").onclick = function() {
    if (player.infinityPoints.gte(player.offlineProdCost) && player.offlineProd < 50) {
        player.infinityPoints = player.infinityPoints.minus(player.offlineProdCost)
        player.offlineProdCost *= 10
        player.offlineProd += 5
        document.getElementById("offlineProd").innerHTML = "Generates "+player.offlineProd+"% > "+Math.max(Math.max(5, player.offlineProd + 5), Math.min(50, player.offlineProd + 5))+"% of your best IP/min from last 10 infinities, works offline<br>Currently: "+shortenMoney(bestRunIppm.times(player.offlineProd/100)) +"IP/min<br> Cost: "+
        formatValue(player.options.notation, player.offlineProdCost, 2, 2)+" IP";
        if (player.offlineProd == 50) document.getElementById("offlineProd").innerHTML = "Generates "+player.offlineProd+"% of your best IP/min from last 10 infinities, works offline<br>Currently: "+shortenMoney(bestRunIppm.times(player.offlineProd/100)) +" IP/min"
    }
}


function updateInfCosts() {

    document.getElementById("infiMult").innerHTML = "Multiply infinity points from all sources by "+getIPMultMultiplier().toFixed(2)+" <br>currently: "+shorten(getIPMult()) +"x<br>Cost: "+shortenCosts(player.infMultCost)+" IP"
    if (document.getElementById("replicantis").style.display == "block" && document.getElementById("infinity").style.display == "block") {
        document.getElementById("replicantichance").setAttribute("ach-tooltip","Level: "+Math.round(player.replicanti.chance*100));
		if (getReplicantiReplicateAmount(true) < 10){
             document.getElementById("replicantichance").innerHTML = "Replicate chance: "+Math.round((getReplicantiReplicateAmount()-1)*100)+"%<br>-> "+Math.round((getReplicantiReplicateAmount(true)-1)*100)+"% Cost: "+shortenCosts(player.replicanti.chanceCost)+" IP"
        } else {
             document.getElementById("replicantichance").innerHTML = "Replicate amount: "+shortenMoney(getReplicantiReplicateAmount())+"x<br>-> "+shortenMoney(getReplicantiReplicateAmount(true))+"x Cost: "+shortenCosts(player.replicanti.chanceCost)+" IP"
        }
        if (player.replicanti.chance>=1 && !player.achievements.includes("ngm4r4"))if (getReplicantiReplicateAmount() < 10){
             document.getElementById("replicantichance").innerHTML = "Replicate chance: "+Math.round((getReplicantiReplicateAmount()-1)*100)+"%<br>(capped)"
        } else {
             document.getElementById("replicantichance").innerHTML = "Replicate amount: "+shortenMoney(getReplicantiReplicateAmount())+"x<br>(capped)"
        }
        document.getElementById("replicantiinterval").setAttribute("ach-tooltip","Level: "+Math.round(Math.log(player.replicanti.interval/1000)/Math.log(0.9)+1));
		let replGalOver = 0
        if (player.timestudy.studies.includes(131)) replGalOver += Math.floor(player.replicanti.gal / 2)
        if (player.timestudy.studies.includes(233)) {
            if (replGalOver !== 0) document.getElementById("replicantimax").innerHTML = "Max Replicanti galaxies: "+player.replicanti.gal+"+"+replGalOver+"<br>+1 Costs: "+shortenCosts(player.replicanti.galCost.dividedBy(player.replicanti.amount.pow(0.3)))+" IP"
            else document.getElementById("replicantimax").innerHTML = "Max Replicanti galaxies: "+player.replicanti.gal+"<br>+1 Costs: "+shortenCosts(player.replicanti.galCost.dividedBy(player.replicanti.amount.pow(0.3)))+" IP"
        } else {
            if (replGalOver !== 0) document.getElementById("replicantimax").innerHTML = "Max Replicanti galaxies: "+player.replicanti.gal+"+"+replGalOver+"<br>+1 Costs: "+shortenCosts(player.replicanti.galCost)+" IP"
            else document.getElementById("replicantimax").innerHTML = "Max Replicanti galaxies: "+player.replicanti.gal+"<br>+1 Costs: "+shortenCosts(player.replicanti.galCost)+" IP"
        }
        document.getElementById("replicantiunlock").innerHTML = "Unlock Replicantis<br>Cost: "+shortenCosts(1e75)+" IP"
        let extraGals = 0
        if (player.timestudy.studies.includes(225)) extraGals += Math.floor(player.replicanti.amount.e / 1000)
        if (player.timestudy.studies.includes(226)) extraGals += Math.floor(player.replicanti.gal / 15)
        if (extraGals !== 0) document.getElementById("replicantireset").innerHTML = "Reset replicanti amount, but get a free galaxy<br>"+player.replicanti.galaxies + "+"+extraGals+ " replicated galaxies created."
        else document.getElementById("replicantireset").innerHTML = (player.replicanti.galaxies !== 1) ? "Reset replicanti amount, but get a free galaxy<br>"+player.replicanti.galaxies + " replicated galaxies created." : "Reset replicanti amount, but get a free galaxy<br>"+player.replicanti.galaxies + " replicated galaxy created."

        document.getElementById("replicantichance").className = (player.infinityPoints.gte(player.replicanti.chanceCost) && (player.replicanti.chance < 1 || player.achievements.includes("ngm4r4"))) ? "storebtn" : "unavailablebtn"
        document.getElementById("replicantiinterval").className = (player.infinityPoints.gte(player.replicanti.intervalCost) && ((player.replicanti.interval !== 50) || player.timestudy.studies.includes(22)) && (player.replicanti.interval !== 1)) ? "storebtn" : "unavailablebtn"
        document.getElementById("replicantimax").className = (player.infinityPoints.gte(player.replicanti.galCost)) ? "storebtn" : "unavailablebtn"
        document.getElementById("replicantireset").className = ((player.replicanti.galaxies < player.replicanti.gal && player.replicanti.amount.gte(Number.MAX_VALUE)) || (player.replicanti.galaxies < Math.floor(player.replicanti.gal * 1.5) && player.replicanti.amount.gte(Number.MAX_VALUE) && player.timestudy.studies.includes(131))) ? "storebtn" : "unavailablebtn"
        document.getElementById("replicantiunlock").className = (player.infinityPoints.gte(1e75)) ? "storebtn" : "unavailablebtn"
    }

    if (document.getElementById("timestudies").style.display == "block" && document.getElementById("eternitystore").style.display == "block") {
        document.getElementById("11desc").textContent = "Currently: "+shortenMoney(timeStudy11())+"x"
        document.getElementById("21desc").textContent = "Currently: +"+shortenMoney(timeStudy21())
		if(player.galacticSacrifice.upgrades.includes(71))document.getElementById("21desc").textContent = "Currently: "+shortenMoney(timeStudy21())+"x"
		if(player.eternities===0 && !player.replicanti.unl)document.getElementById("21desc").textContent = "Req: Unlock Replicanti or Eternitied at least once";
        document.getElementById("32desc").textContent = "You gain "+Math.max(player.resets, 1)+"x more infinitied stat (based on dimension boosts)"
        document.getElementById("41desc").textContent = "Currently: "+shortenMoney(timeStudy41())+"x"
        document.getElementById("51desc").textContent = "You gain "+shortenCosts(1e15)+"x more IP"
        document.getElementById("53desc").textContent = shortenMoney(timeStudy53())
        document.getElementById("71desc").textContent = "Currently: "+shortenMoney(timeStudy71())+"x"
        document.getElementById("72desc").textContent = "Currently: "+shortenMoney(timeStudy72())+"x"
        document.getElementById("73desc").textContent = "Currently: "+shortenMoney(timeStudy73())+"x"
        document.getElementById("81desc").textContent = "Currently: ^"+shortenMoney(timeStudy81())
        document.getElementById("82desc").textContent = "Currently: "+shortenMoney(timeStudy82())+"x"
        document.getElementById("83desc").textContent = "Currently: "+shortenMoney(timeStudy83())+"x"
        document.getElementById("83desc2").textContent = "(applied after powerer)"
        if(player.timeless.upgrades.includes(15))document.getElementById("83desc2").textContent = "(applied before powerer)"
        document.getElementById("91desc").textContent = "Currently: "+shortenMoney(timeStudy91())+"x"
        document.getElementById("92desc").textContent = "Currently: "+shortenMoney(timeStudy92())+"x"
        document.getElementById("93desc").textContent = "Currently: "+shortenMoney(timeStudy93())+"x"
        document.getElementById("101desc").textContent = "Currently: "+shortenMoney(timeStudy101())+"x"
        document.getElementById("102desc").textContent = "Currently: "+shortenMoney(timeStudy102())+"x"
        document.getElementById("103desc").textContent = "Currently: "+shortenMoney(timeStudy103())+"x"
        document.getElementById("121desc").textContent = "Currently: "+((253 - averageEp.dividedBy(player.epmult).dividedBy(10).min(248).max(3))/5).toFixed(1)+"x"
        document.getElementById("123desc").textContent = "Currently: "+Math.sqrt(1.39*player.thisEternity/10).toFixed(1)+"x"
        document.getElementById("141desc").textContent = "Currently: "+shortenMoney(new Decimal(1e45).dividedBy(Decimal.pow(15, Math.log(player.thisInfinityTime)*Math.pow(player.thisInfinityTime, 0.125))).max(1))+"x"
        document.getElementById("142desc").textContent = "You gain "+shortenCosts(1e25)+"x more IP"
        document.getElementById("143desc").textContent = "Currently: "+shortenMoney(Decimal.pow(15, Math.log(player.thisInfinityTime)*Math.pow(player.thisInfinityTime, 0.125)))+"x"
        document.getElementById("151desc").textContent = shortenCosts(timeStudy151())+"x multiplier on all Time dimensions"
        document.getElementById("161desc").textContent = shortenCosts(timeStudy161())+"x multiplier on all normal dimensions"
        document.getElementById("162desc").textContent = shortenCosts(timeStudy162())+"x multiplier on all Infinity dimensions"
        document.getElementById("191desc").textContent = "Currently: "+shortenMoney(timeStudy191())+"x"
        document.getElementById("192desc").textContent = "Uncap replicanti."
        document.getElementById("193desc").textContent = "Currently: "+shortenMoney(timeStudy193())+"x"
        document.getElementById("212desc").textContent = "Currently: "+((Math.pow(player.timeShards.max(2).log2(), 0.005)-1)*100).toFixed(2)+"%"
        document.getElementById("214desc").textContent = "Currently: "+shortenMoney(timeStudy214())+"x"

        if (player.etercreq !== 1) document.getElementById("ec1unl").innerHTML = "Eternity Challenge 1<span>Requirement: "+(ECTimesCompleted("eterc1")+1)*20000+" Eternities<span>Cost: 30 Time Theorems"
        else document.getElementById("ec1unl").innerHTML = "Eternity Challenge 1<span>Cost: 30 Time Theorems"
        if (player.etercreq !== 2) document.getElementById("ec2unl").innerHTML = "Eternity Challenge 2<span>Requirement: "+(1300+(ECTimesCompleted("eterc2")*150))+" Tickspeed upgrades gained from time dimensions<span>Cost: 35 Time Theorems"
        else document.getElementById("ec2unl").innerHTML = "Eternity Challenge 2<span>Cost: 35 Time Theorems"
        if (player.etercreq !== 3) document.getElementById("ec3unl").innerHTML = "Eternity Challenge 3<span>Requirement: "+(17300+(ECTimesCompleted("eterc3")*1250))+" 8th dimensions<span>Cost: 40 Time Theorems"
        else document.getElementById("ec3unl").innerHTML = "Eternity Challenge 3<span>Cost: 40 Time Theorems"
        if (player.etercreq !== 4) document.getElementById("ec4unl").innerHTML = "Eternity Challenge 4<span>Requirement: "+(1e8 + (ECTimesCompleted("eterc4")*5e7)).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",")+" infinities<span>Cost: 70 Time Theorems"
        else document.getElementById("ec4unl").innerHTML = "Eternity Challenge 4<span>Cost: 70 Time Theorems"
        if (player.etercreq !== 5) document.getElementById("ec5unl").innerHTML = "Eternity Challenge 5<span>Requirement: "+Math.ceil(52+(Math.pow(ECTimesCompleted("eterc5"),0.72)*3))+" galaxies<span>Cost: 130 Time Theorems"
        else document.getElementById("ec5unl").innerHTML = "Eternity Challenge 5<span>Cost: 130 Time Theorems"
        if (player.etercreq !== 6) document.getElementById("ec6unl").innerHTML = "Eternity Challenge 6<span>Requirement: "+(40+(ECTimesCompleted("eterc6")*5))+" replicanti galaxies<span>Cost: 85 Time Theorems"
        else document.getElementById("ec6unl").innerHTML = "Eternity Challenge 6<span>Cost: 85 Time Theorems"
        if (player.etercreq !== 7) document.getElementById("ec7unl").innerHTML = "Eternity Challenge 7<span>Requirement: "+shortenCosts(new Decimal("1e500000").times(new Decimal("1e300000").pow(ECTimesCompleted("eterc7"))))+" antimatter <span>Cost: 115 Time Theorems"
        else document.getElementById("ec7unl").innerHTML = "Eternity Challenge 7<span>Cost: 115 Time Theorems"
        if (player.etercreq !== 8) document.getElementById("ec8unl").innerHTML = "Eternity Challenge 8<span>Requirement: "+shortenCosts(new Decimal("1e4000").times(new Decimal("1e1000").pow(ECTimesCompleted("eterc8"))))+" IP <span>Cost: 115 Time Theorems"
        else document.getElementById("ec8unl").innerHTML = "Eternity Challenge 8<span>Cost: 115 Time Theorems"
        if (player.etercreq !== 9) document.getElementById("ec9unl").innerHTML = "Eternity Challenge 9<span>Requirement: "+shortenCosts(new Decimal("1e17500").times(new Decimal("1e2000").pow(ECTimesCompleted("eterc9"))))+" infinity power<span>Cost: 415 Time Theorems"
        else document.getElementById("ec9unl").innerHTML = "Eternity Challenge 9<span>Cost: 415 Time Theorems"
        if (player.etercreq !== 10) document.getElementById("ec10unl").innerHTML = "Eternity Challenge 10<span>Requirement: "+shortenCosts(new Decimal("1e100").times(new Decimal("1e20").pow(ECTimesCompleted("eterc10"))))+" EP<span>Cost: 550 Time Theorems"
        else document.getElementById("ec10unl").innerHTML = "Eternity Challenge 10<span>Cost: 550 Time Theorems"

        document.getElementById("ec11unl").innerHTML = "Eternity Challenge 11<span>Requirement: Use only the Normal Dimension path<span>Cost: 1 Time Theorem"
        document.getElementById("ec12unl").innerHTML = "Eternity Challenge 12<span>Requirement: Use only the Time Dimension path<span>Cost: 1 Time Theorem"

        if (player.dilation.studies.includes(1)) document.getElementById("dilstudy1").innerHTML = "Unlock time dilation<span>Cost: 5000 Time Theorems"
        else document.getElementById("dilstudy1").innerHTML = "Unlock time dilation<span>Requirement: 5 EC11 and EC12 completions and 13000 total theorems<span>Cost: 5000 Time Theorems"
    }
}



// Replicanti stuff

function unlockReplicantis() {
    if (player.infinityPoints.gte(1e75)) {
        document.getElementById("replicantidiv").style.display="inline-block"
        document.getElementById("replicantiunlock").style.display="none"
        player.replicanti.unl = true
        player.replicanti.amount = new Decimal(1)
        player.infinityPoints = player.infinityPoints.minus(1e75)
    }
}

function upgradeReplicantiChance() {
    if (player.infinityPoints.gte(player.replicanti.chanceCost) && (player.replicanti.chance < 1 || player.achievements.includes("ngm4r4")) && player.eterc8repl !== 0) {
        player.infinityPoints = player.infinityPoints.minus(player.replicanti.chanceCost)
        player.replicanti.chanceCost = player.replicanti.chanceCost.times(1e15)
        player.replicanti.chance += 0.01
        if (player.currentEternityChall == "eterc8") player.eterc8repl-=1
        document.getElementById("eterc8repl").textContent = "You have "+player.eterc8repl+" purchases left."
    }
}

function upgradeReplicantiInterval() {
    if (player.infinityPoints.gte(player.replicanti.intervalCost) && (player.replicanti.interval > 50 || player.timestudy.studies.includes(22)) && player.replicanti.interval !== 1 && player.eterc8repl !== 0) {
        player.infinityPoints = player.infinityPoints.minus(player.replicanti.intervalCost)
        player.replicanti.intervalCost = player.replicanti.intervalCost.times(1e10)
        player.replicanti.interval *= 0.9
        if (!player.timestudy.studies.includes(22) && player.replicanti.interval < 50) player.replicanti.interval = 50
        if (player.timestudy.studies.includes(22) && player.replicanti.interval < 1) player.replicanti.interval = 1
        var places = Math.floor(Math.log10(player.replicanti.interval/1000)) * (-1)
        if (player.currentEternityChall == "eterc8") player.eterc8repl-=1
        document.getElementById("eterc8repl").textContent = "You have "+player.eterc8repl+" purchases left."
    }
}

function upgradeReplicantiGalaxy() {
    let cost = player.replicanti.galCost
    if (player.timestudy.studies.includes(233)) cost = cost.dividedBy(player.replicanti.amount.pow(0.3))
    if (player.infinityPoints.gte(cost) && player.eterc8repl !== 0) {
        player.infinityPoints = player.infinityPoints.minus(cost)
        if (player.currentEternityChall == "eterc6") player.replicanti.galCost = player.replicanti.galCost.times(Decimal.pow(1e2, player.replicanti.gal)).times(1e2)
        else player.replicanti.galCost = player.replicanti.galCost.times(Decimal.pow(1e5, player.replicanti.gal)).times(1e25)
        if (player.replicanti.gal >= 100) player.replicanti.galCost = player.replicanti.galCost.times(Decimal.pow(1e50, player.replicanti.gal - 95))
        player.replicanti.gal += 1
        if (player.currentEternityChall == "eterc8") player.eterc8repl-=1
        document.getElementById("eterc8repl").textContent = "You have "+player.eterc8repl+" purchases left."
        return true
    }
    return false
}


function replicantiGalaxy() {
    if (player.replicanti.amount.gte(Number.MAX_VALUE) && (!player.timestudy.studies.includes(131) ? player.replicanti.galaxies < player.replicanti.gal : player.replicanti.galaxies < Math.floor(player.replicanti.gal * 1.5))) {
        if (player.achievements.includes("r126")) player.replicanti.amount = player.replicanti.amount.dividedBy(Number.MAX_VALUE)
        else player.replicanti.amount = new Decimal(1)
        player.replicanti.galaxies += 1
        player.galaxies-=1
        galaxyReset()

    }
}



function updateMilestones() {
    var milestoneRequirements = [1, 2, 3, 4, 5, 6, 7, 9, 11, 12, 13, 14, 15, 16, 17, 18, 20, 25, 30, 40, 50, 60, 80, 100]
    for (i=0; i<milestoneRequirements.length; i++) {
        var name = "reward" + i;
        if (player.eternities >= milestoneRequirements[i]) {
            document.getElementById(name).className = "milestonereward"
        } else {
            document.getElementById(name).className = "milestonerewardlocked"
        }
    }
}

function replicantiGalaxyAutoToggle() {
    if (player.replicanti.galaxybuyer) {
        player.replicanti.galaxybuyer = false
        if (player.timestudy.studies.includes(131)) document.getElementById("replicantiresettoggle").textContent = "Auto galaxy OFF (disabled)"
        else document.getElementById("replicantiresettoggle").textContent = "Auto galaxy OFF"
    } else {
        player.replicanti.galaxybuyer = true
        if (player.timestudy.studies.includes(131)) document.getElementById("replicantiresettoggle").textContent = "Auto galaxy ON (disabled)"
        else document.getElementById("replicantiresettoggle").textContent = "Auto galaxy ON"
    }
}

function infMultAutoToggle() {
    if (player.infMultBuyer) {
        player.infMultBuyer = false
        document.getElementById("infmultbuyer").textContent = "Autobuy IP mult OFF"
    } else {
        player.infMultBuyer = true
        document.getElementById("infmultbuyer").textContent = "Autobuy IP mult ON"
    }
}


function toggleCrunchMode() {
    if (player.autoCrunchMode == "amount") {
        player.autoCrunchMode = "time"
        document.getElementById("togglecrunchmode").textContent = "Auto crunch mode: time"
        document.getElementById("limittext").textContent = "Seconds between crunches:"
    } else if (player.autoCrunchMode == "time"){
        player.autoCrunchMode = "relative"
        document.getElementById("togglecrunchmode").textContent = "Auto crunch mode: X times last crunch"
        document.getElementById("limittext").textContent = "X times last crunch:"
    } else {
        player.autoCrunchMode = "amount"
        document.getElementById("togglecrunchmode").textContent = "Auto crunch mode: amount"
        document.getElementById("limittext").textContent = "Amount of IP to wait until reset:"
    }
}

function toggleEternityConf() {
    if (player.options.eternityconfirm) {
        player.options.eternityconfirm = false
        document.getElementById("eternityconf").textContent = "Eternity confirmation OFF"
    } else {
        player.options.eternityconfirm = true
        document.getElementById("eternityconf").textContent = "Eternity confirmation ON"
    }
}


function toggleReplAuto(i) {
    if (i == "chance") {
        if (player.replicanti.auto[0]) {
            player.replicanti.auto[0] = false
            document.getElementById("replauto1").textContent = "Auto: OFF"
        } else {
            player.replicanti.auto[0] = true
            document.getElementById("replauto1").textContent = "Auto: ON"
        }
    } else if (i == "interval") {
        if (player.replicanti.auto[1]) {
            player.replicanti.auto[1] = false
            document.getElementById("replauto2").textContent = "Auto: OFF"
        } else {
            player.replicanti.auto[1] = true
            document.getElementById("replauto2").textContent = "Auto: ON"
        }
    } else if (i == "galaxy") {
        if (player.replicanti.auto[2]) {
            player.replicanti.auto[2] = false
            document.getElementById("replauto3").textContent = "Auto: OFF"
        } else {
            player.replicanti.auto[2] = true
            document.getElementById("replauto3").textContent = "Auto: ON"
        }
    }
}




function toggleCommas() {
    player.options.commas = !player.options.commas

    if (player.options.commas) document.getElementById("commas").textContent = "Commas on exponents"
    else document.getElementById("commas").textContent = "Notation on exponents"
}






buyAutobuyer = function(id) {
    if (player.infinityPoints.lt(player.autobuyers[id].cost)) return false;
    if (player.autobuyers[id].bulk >= 1e100) return false;
    player.infinityPoints = player.infinityPoints.minus(player.autobuyers[id].cost);
    if (player.autobuyers[id].interval <= 100) {
        player.autobuyers[id].bulk = Math.min(player.autobuyers[id].bulk * 2, 1e100);
        player.autobuyers[id].cost = Math.ceil(2.4*player.autobuyers[id].cost);
        var b1 = true;
	    for (let i=0;i<8;i++) {
            if (player.autobuyers[i].bulk < 512) b1 = false;
        }
        if (b1) giveAchievement("Bulked up");
    } else {
        player.autobuyers[id].interval = Math.max(player.autobuyers[id].interval*0.6, 100);
        if (player.autobuyers[id].interval > 120) player.autobuyers[id].cost *= 2; //if your last purchase wont be very strong, dont double the cost
    }
    updateAutobuyers();
}

document.getElementById("buyerBtn1").onclick = function () {
    buyAutobuyer(0);
}

document.getElementById("buyerBtn2").onclick = function () {

    buyAutobuyer(1);
}

document.getElementById("buyerBtn3").onclick = function () {
    buyAutobuyer(2);
}

document.getElementById("buyerBtn4").onclick = function () {
    buyAutobuyer(3);
}

document.getElementById("buyerBtn5").onclick = function () {
    buyAutobuyer(4);
}

document.getElementById("buyerBtn6").onclick = function () {
    buyAutobuyer(5);
}

document.getElementById("buyerBtn7").onclick = function () {
    buyAutobuyer(6);
}

document.getElementById("buyerBtn8").onclick = function () {
    buyAutobuyer(7);
}

document.getElementById("buyerBtnTickSpeed").onclick = function () {
    buyAutobuyer(8);
}

document.getElementById("buyerBtnDimBoost").onclick = function () {
    buyAutobuyer(9);
}

document.getElementById("buyerBtnGalaxies").onclick = function () {
    buyAutobuyer(10);
}

document.getElementById("buyerBtnInf").onclick = function () {
    buyAutobuyer(11);
}

document.getElementById("buyerBtnSac").onclick = function () {
    buyAutobuyer(12);
}

document.getElementById("buyerBtnGalSac").onclick = function () {
    buyAutobuyer(13);
}

toggleAutobuyerTarget = function(id) {
    if (player.autobuyers[id-1].target == id) {
        player.autobuyers[id-1].target = 10 + id
        document.getElementById("toggleBtn" + id).textContent = "Buys until 10"
    } else {
        player.autobuyers[id-1].target = id
        document.getElementById("toggleBtn" + id).textContent = "Buys singles"
    }
}

document.getElementById("toggleBtn1").onclick = function () {
    toggleAutobuyerTarget(1)
}

document.getElementById("toggleBtn2").onclick = function () {
    toggleAutobuyerTarget(2)
}

document.getElementById("toggleBtn3").onclick = function () {
    toggleAutobuyerTarget(3)
}

document.getElementById("toggleBtn4").onclick = function () {
    toggleAutobuyerTarget(4)
}

document.getElementById("toggleBtn5").onclick = function () {
    toggleAutobuyerTarget(5)
}

document.getElementById("toggleBtn6").onclick = function () {
    toggleAutobuyerTarget(6)
}

document.getElementById("toggleBtn7").onclick = function () {
    toggleAutobuyerTarget(7)
}

document.getElementById("toggleBtn8").onclick = function () {
    toggleAutobuyerTarget(8)
}

document.getElementById("toggleBtnTickSpeed").onclick = function () {
    if (player.autobuyers[8].target == 1) {
        player.autobuyers[8].target = 10
        document.getElementById("toggleBtnTickSpeed").textContent = "Buys max"
    } else {
        player.autobuyers[8].target = 1
        document.getElementById("toggleBtnTickSpeed").textContent = "Buys singles"
    }
}















document.getElementById("secondSoftReset").onclick = function() {
    if (player.currentEternityChall == "eterc6") return
    var bool = player.currentChallenge != "challenge11" && player.currentChallenge != "postc4" && player.currentChallenge != "postc7" && player.currentChallenge != "postc9" && (player.break || player.money.lte(Number.MAX_VALUE))
    if (player.currentChallenge == "challenge4" ? player.sixthAmount >= getGalaxyRequirement() && bool : player.eightAmount >= getGalaxyRequirement() && bool) {
        if (player.eternities >= 9 && !shiftDown) maxBuyGalaxies(true);
        else galaxyReset();
    }
}

function getIPMult () {
    let mult = Decimal.pow(getIPMultMultiplier(),player.infMultCost.log10()-1);
    return mult;
}

let getIPMultMultiplier = function () {
  let ret = 2;
  if (player.galacticSacrifice.upgrades.includes(53)) ret += Math.pow(1.25,-1e3/player.galacticSacrifice.galaxyPoints.max(1).log10())
  return ret
}

function setInitialDimensionPower () {
  player.firstPow = getDimensionBoostPower().pow(player.resets)
  player.secondPow = getDimensionBoostPower().pow(player.resets - 1).max(1)
  player.thirdPow = getDimensionBoostPower().pow(player.resets - 2).max(1)
  player.fourthPow = getDimensionBoostPower().pow(player.resets - 3).max(1)
  player.fifthPow = getDimensionBoostPower().pow(player.resets - 4).max(1)
  player.sixthPow = getDimensionBoostPower().pow(player.resets - 5).max(1)
  player.seventhPow = getDimensionBoostPower().pow(player.resets - 6).max(1)
  player.eightPow = getDimensionBoostPower().pow(player.resets - 7).max(1)
}

function galaxyReset() {

    if (autoS) auto = false;
    autoS = true;
    if (player.sacrificed == 0) giveAchievement("I don't believe in Gods");
    player = {
        money: player.achievements.includes("r111") ? player.money : new Decimal(10),
        tickSpeedCost: new Decimal(1000),
        tickspeed: new Decimal(10000),
        firstCost: new Decimal(10),
        secondCost: new Decimal(100),
        thirdCost: new Decimal(10000),
        fourthCost: new Decimal(1000000),
        fifthCost: new Decimal(1e9),
        sixthCost: new Decimal(1e13),
        seventhCost: new Decimal(1e18),
        eightCost: new Decimal(1e24),
        firstAmount: new Decimal(0),
        secondAmount: new Decimal(0),
        thirdAmount: new Decimal(0),
        fourthAmount: new Decimal(0),
        firstBought: 0,
        secondBought: 0,
        thirdBought: 0,
        fourthBought: 0,
        firstTotalBought: 0,
        secondTotalBought: 0,
        thirdTotalBought: 0,
        fourthTotalBought: 0,
        fifthAmount: new Decimal(0),
        sixthAmount: new Decimal(0),
        seventhAmount: new Decimal(0),
        eightAmount: new Decimal(0),
        fifthBought: 0,
        sixthBought: 0,
        seventhBought: 0,
        eightBought: 0,
        fifthTotalBought: 0,
        sixthTotalBought: 0,
        seventhTotalBought: 0,
        eightTotalBought: 0,
        firstPow: new Decimal(1),
        secondPow: new Decimal(1),
        thirdPow: new Decimal(1),
        fourthPow: new Decimal(1),
        fifthPow: new Decimal(1),
        sixthPow: new Decimal(1),
        seventhPow: new Decimal(1),
        eightPow: new Decimal(1),
        sacrificed: new Decimal(0),
        achievements: player.achievements,
        challenges: player.challenges,
        currentChallenge: player.currentChallenge,
        infinityUpgrades: player.infinityUpgrades,
        infinityPoints: player.infinityPoints,
        infinitied: player.infinitied,
        infinitiedBank: player.infinitiedBank,
        totalTimePlayed: player.totalTimePlayed,
        bestInfinityTime: player.bestInfinityTime,
        thisInfinityTime: player.thisInfinityTime,
        resets: 0,
        galaxies: player.galaxies + 1,
        totalmoney: player.totalmoney,
        tickDecrease: player.tickDecrease - 0.03,
        interval: null,
        lastUpdate: player.lastUpdate,
        achPow: player.achPow,
        newsArray: player.newsArray,
        autobuyers: player.autobuyers,
        costMultipliers: [new Decimal(1e3), new Decimal(1e4), new Decimal(1e5), new Decimal(1e6), new Decimal(1e8), new Decimal(1e10), new Decimal(1e12), new Decimal(1e15)],
        tickspeedMultiplier: new Decimal(10),
        chall2Pow: player.chall2Pow,
        chall3Pow: new Decimal(0.01),
        matter: new Decimal(0),
        chall11Pow: new Decimal(1),
        partInfinityPoint: player.partInfinityPoint,
        partInfinitied: player.partInfinitied,
        break: player.break,
        challengeTimes: player.challengeTimes,
        infchallengeTimes: player.infchallengeTimes,
        lastTenRuns: player.lastTenRuns,
        lastTenEternities: player.lastTenEternities,
        infMult: player.infMult,
        infMultCost: player.infMultCost,
        tickSpeedMultDecrease: player.tickSpeedMultDecrease,
        tickSpeedMultDecreaseCost: player.tickSpeedMultDecreaseCost,
        dimensionMultDecrease: player.dimensionMultDecrease,
        dimensionMultDecreaseCost: player.dimensionMultDecreaseCost,
        version: player.version,
        overXGalaxies: player.overXGalaxies,
        spreadingCancer: player.spreadingCancer,
        infDimensionsUnlocked: player.infDimensionsUnlocked,
        infinityPower: player.infinityPower,
        postChallUnlocked: player.postChallUnlocked,
        postC6Tier: 1,
        postC3Reward: new Decimal(1),
        infinityDimension1: player.infinityDimension1,
        infinityDimension2: player.infinityDimension2,
        infinityDimension3: player.infinityDimension3,
        infinityDimension4: player.infinityDimension4,
        infinityDimension5: player.infinityDimension5,
        infinityDimension6: player.infinityDimension6,
        infinityDimension7: player.infinityDimension7,
        infinityDimension8: player.infinityDimension8,
        infDimBuyers: player.infDimBuyers,
        timeShards: new Decimal(0),
        tickThreshold: new Decimal(1),
        timeDimension1: player.timeDimension1,
        timeDimension2: player.timeDimension2,
        timeDimension3: player.timeDimension3,
        timeDimension4: player.timeDimension4,
        timeDimension5: player.timeDimension5,
        timeDimension6: player.timeDimension6,
        timeDimension7: player.timeDimension7,
        timeDimension8: player.timeDimension8,
        eternityPoints: player.eternityPoints,
        eternities: player.eternities,
        thisEternity: player.thisEternity,
        bestEternity: player.bestEternity,
        eternityUpgrades: player.eternityUpgrades,
        epmult: player.epmult,
        epmultCost: player.epmultCost,
        totalTickGained: 0,
        offlineProd: player.offlineProd,
        offlineProdCost: player.offlineProdCost,
        extraDimPowerIncrease: player.extraDimPowerIncrease,
        dimPowerIncreaseCost: player.dimPowerIncreaseCost,
        challengeTarget: player.challengeTarget,
        replicanti: player.replicanti,
        timestudy: player.timestudy,
        eternityChalls: player.eternityChalls,
        eternityChallGoal: player.eternityChallGoal,
        currentEternityChall: player.currentEternityChall,
        eternityChallUnlocked: player.eternityChallUnlocked,
        etercreq: player.etercreq,
        autoIP: player.autoIP,
        autoTime: player.autoTime,
        infMultBuyer: player.infMultBuyer,
        autoCrunchMode: player.autoCrunchMode,
        respec: player.respec,
        eternityBuyer: player.eternityBuyer,
        eterc8ids: player.eterc8ids,
        eterc8repl: player.eterc8repl,
        tickBoughtThisInf: {
          current: player.tickBoughtThisInf.current,
          pastResets: [{'resets': 0,
          'bought': player.tickBoughtThisInf.current}]
        },
        dimlife: player.dimlife,
        dead: player.dead,
        dilation: player.dilation,
        why: player.why,
	      galacticSacrifice: player.galacticSacrifice,
        options: player.options,
		
	// for aarex modifications
	aarexModifications: {
		ngmX: 4,
		ngmm: 3,
		ngm4r: 1,
		newGame4MinusRespeccedVersion: newGame4MinusRespeccedVersion

	},
	
	tickspeedBoosts: 0,
	tdBoosts: 0,

    timeless: player.timeless,
    };
	resetTimeDimensions(1);
    if (player.currentChallenge == "challenge10" || player.currentChallenge == "postc4") {
        player.thirdCost = new Decimal(100)
        player.fourthCost = new Decimal(500)
        player.fifthCost = new Decimal(2500)
        player.sixthCost = new Decimal(2e4)
        player.seventhCost = new Decimal(2e5)
        player.eightCost = new Decimal(4e6)
    }
    if (player.currentChallenge == "challenge10" || player.currentChallenge == "postc4") player.costMultipliers = [new Decimal(1e3),new Decimal(5e3),new Decimal(1e4),new Decimal(1.2e4),new Decimal(1.8e4),new Decimal(2.6e4),new Decimal(3.2e4),new Decimal(4.2e4)];

    if (player.resets == 0 && player.currentChallenge == "") {
        if (player.infinityUpgrades.includes("skipReset1")) player.resets++;
        if (player.infinityUpgrades.includes("skipReset2")) player.resets++;
        if (player.infinityUpgrades.includes("skipReset3")) player.resets++;
        if (player.infinityUpgrades.includes("skipResetGalaxy")) {
            player.resets++;
            if (player.galaxies == 0) player.galaxies = 1
        }
		if (player.resets > 0)player.tickspeedBoosts = player.tdBoosts = Math.pow(2,player.resets);
    }
    if (player.currentChallenge == "postc5") {
        player.eightAmount = new Decimal(1);
        player.eightBought = 1;
        player.resets = 4;
    }

    decreaseDimCosts();

    setInitialDimensionPower();


    if (player.options.notation == "Emojis") player.spreadingCancer+=1;
    if (player.spreadingCancer >= 10) giveAchievement("Spreading Cancer")
    if (player.spreadingCancer >= 1000000) giveAchievement("Cancer = Spread")
    if (player.achievements.includes("r36")) player.tickspeed = player.tickspeed.times(0.98);
    if (player.achievements.includes("r45")) player.tickspeed = player.tickspeed.times(0.98);
    if (player.achievements.includes("r83")) player.tickspeed = player.tickspeed.times(Decimal.pow(0.95,player.galaxies));

    if (player.eternities < 30) {
        document.getElementById("secondRow").style.display = "none";
        document.getElementById("thirdRow").style.display = "none";
        document.getElementById("tickSpeed").style.visibility = "hidden";
        document.getElementById("tickSpeedMax").style.visibility = "hidden";
        document.getElementById("tickLabel").style.visibility = "hidden";
        document.getElementById("tickSpeedAmount").style.visibility = "hidden";
        document.getElementById("tickSpeedPurchases").style.visibility = "hidden";
        document.getElementById("fourthRow").style.display = "none";
        document.getElementById("fifthRow").style.display = "none";
        document.getElementById("sixthRow").style.display = "none";
        document.getElementById("seventhRow").style.display = "none";
        document.getElementById("eightRow").style.display = "none";
    }

    if (player.galaxies >= 50) giveAchievement("YOU CAN GET 50 GALAXIES!??")
    if (player.galaxies >= 2) giveAchievement("Double Galaxy");
    if (player.galaxies >= 1) giveAchievement("You got past The Big Wall");
    if (player.challenges.includes("challenge1")) player.money = new Decimal(100).max(player.money)
    if (player.achievements.includes("r37")) player.money = new Decimal(1000).max(player.money);
    if (player.achievements.includes("r54")) player.money = new Decimal(2e5).max(player.money);
    if (player.achievements.includes("r55")) player.money = new Decimal(1e10).max(player.money);
    if (player.achievements.includes("r78")) player.money = new Decimal(1e25).max(player.money);
    player.tickspeed = player.tickspeed.times(Decimal.pow(getTickSpeedMultiplier(), player.totalTickGained))
    player.postC3Reward = player.postC3Reward.times(Decimal.pow(getPostC3RewardMult(), player.totalTickGained))
    if (player.achievements.includes("r66")) player.tickspeed = player.tickspeed.times(0.98);
    if (player.galaxies >= 540 && player.replicanti.galaxies == 0) giveAchievement("Unique snowflakes")
    updateTickSpeed();
};

document.getElementById("exportbtn").onclick = function () {
    let output = document.getElementById('exportOutput');
    let parent = output.parentElement;

    parent.style.display = "";
    output.value = btoa(JSON.stringify(player, function(k, v) { return (v === Infinity) ? "Infinity" : v; }));

    output.onblur = function() {
        parent.style.display = "none";
    }

    output.focus();
    output.select();

    try {
        if (document.execCommand('copy')) {
            $.notify("exported to clipboard", "info");
            output.blur();
        }
    } catch(ex) {
        // well, we tried.
    }
};


document.getElementById("save").onclick = function () {
    saved++
    if (saved > 99) giveAchievement("Just in case")
    save_game();
};

document.getElementById("load").onclick = function () {
    closeToolTip();
	for (var i = 0; i < 3; i++) {
		var _break = player.break;
        player.break = true;
        if (currentSave === i) document.querySelector("#save" + (i + 1) + " .save_antimatter").textContent = "Antimatter: " + shortenMoney(player.money);
        else document.querySelector("#save" + (i + 1) + " .save_antimatter").textContent = "Antimatter: " + shortenMoney(saves[i] ? new Decimal(saves[i].money) : 10);
		player.break = _break;
	}

	document.querySelectorAll(".save_selected").forEach(function(el) {
		el.style.display = "none";
	});

	document.querySelector("#save" + (currentSave + 1) + " .save_selected").style.display = "inline";

    document.getElementById("loadmenu").style.display = "flex";
};

document.getElementById("animationoptionsbtn").onclick = function () {
    closeToolTip();
    document.getElementById("animationoptions").style.display = "flex";
};

function verify_save(obj) {
    if (typeof obj != 'object') return false;


    return true;
}

document.getElementById("importbtn").onclick = function () {
    var save_data = prompt("Input your save. (your current save file will be overwritten!)");
    if (save_data.constructor !== String) save_data = "";
	if (save_data=="f" || save_data=="F"){giveAchievement("It pays to have respect");return;}
    if (sha512_256(save_data.replace(/\s/g, '').toUpperCase()) === "80b7fdc794f5dfc944da6a445a3f21a2d0f7c974d044f2ea25713037e96af9e3") {
        document.getElementById("body").style.animation = "barrelRoll 5s 1";
        giveAchievement("Do a barrel roll!")
        setTimeout(function(){ document.getElementById("body").style.animation = ""; }, 5000)
    }
    if (sha512_256(save_data.replace(/\s/g, '').toUpperCase()) === "857876556a230da15fe1bb6f410ca8dbc9274de47c1a847c2281a7103dd2c274") giveAchievement("So do I");
    if (sha512_256(save_data) === "de24687ee7ba1acd8f5dc8f71d41a3d4b7f14432fff53a4d4166e7eea48a88c0") {
        player.options.theme = "S1";
        player.options.secretThemeKey = save_data;
        setTheme(player.options.theme);
    } else if (sha512_256(save_data) === "76269d18c05c9ebec8a990a096cee046dea042a0421f8ab81d17f34dd1cdbdbf") {
        player.options.theme = "S2";
        player.options.secretThemeKey = save_data;
        setTheme(player.options.theme);
    } else if (sha512_256(save_data) === "d764e9a1d1e18081be19f3483b537ae1159ab40d10e096df1d9e857d68d6ba7a") {
        player.options.theme = "S3";
        player.options.secretThemeKey = save_data;
        setTheme(player.options.theme);
    } else if (sha512_256(save_data) === "ae0199482ecfa538a03eb37c67866e67a11f1832516c26c7939e971e514d40c5") {
        player.options.theme = "S4";
        player.options.secretThemeKey = save_data;
        setTheme(player.options.theme);
    }  else if (sha512_256(save_data) === "7a668b64cdfe1bcdf7a38d3858429ee21290268de66b9784afba27dc5225ce28") {
        player.options.theme = "S5";
        player.options.secretThemeKey = save_data;
        setTheme(player.options.theme);
    } else {
        save_data = JSON.parse(atob(save_data), function(k, v) { return (v === Infinity) ? "Infinity" : v; });
        if(verify_save(save_data)) forceHardReset = true
        if(verify_save(save_data)) document.getElementById("reset").click();
        forceHardReset = false
        if (!save_data || !verify_save(save_data)) {
            alert('could not load the save..');
            load_custom_game();
            return;
		}
        saved = 0;
        totalMult = 1
        currentMult = 1
        infinitiedMult = 1
        achievementMult = 1
        challengeMult = 1
        unspentBonus = 1
        infDimPow = 1
        postc10Mult = new Decimal(0)
        mult18 = new Decimal(1)
        ec10bonus = new Decimal(1)
        timeMultNum = 1
        timeMultNum2 = 1
        player = save_data;
        save_game();
        load_game();
        updateChallenges()
        transformSaveToDecimal()
    }
};




document.getElementById("reset").onclick = function () {
    if (forceHardReset) {
        if (window.location.href.split("//")[1].length > 20) set_save('ngm4rep', currentSave, defaultStart);
        else set_save('ngm4rep', currentSave, defaultStart);
        player = defaultStart
        infDimPow = 1;
        save_game();
        load_game();
        updateCosts();

        document.getElementById("secondRow").style.display = "none";
        document.getElementById("thirdRow").style.display = "none";
        document.getElementById("tickSpeed").style.visibility = "hidden";
        document.getElementById("tickSpeedMax").style.visibility = "hidden";
        document.getElementById("tickLabel").style.visibility = "hidden";
        document.getElementById("tickSpeedAmount").style.visibility = "hidden";
        document.getElementById("tickSpeedPurchases").style.visibility = "hidden";
        document.getElementById("fourthRow").style.display = "none";
        document.getElementById("fifthRow").style.display = "none";
        document.getElementById("sixthRow").style.display = "none";
        document.getElementById("seventhRow").style.display = "none";
        document.getElementById("eightRow").style.display = "none";
        showDimTab('antimatterdimensions')
        updateTickSpeed();
        updateDimensions();
        updateChallenges();
        updateAutobuyers();
    } else if (confirm("Do you really want to erase all your progress?")) {
        if (window.location.href.split("//")[1].length > 20) set_save('ngm4rep', currentSave, defaultStart);
        else set_save('ngm4rep', currentSave, defaultStart);
        player = defaultStart
        infDimPow = 1;
        save_game();
        load_game();
        updateCosts();

        document.getElementById("secondRow").style.display = "none";
        document.getElementById("thirdRow").style.display = "none";
        document.getElementById("tickSpeed").style.visibility = "hidden";
        document.getElementById("tickSpeedMax").style.visibility = "hidden";
        document.getElementById("tickLabel").style.visibility = "hidden";
        document.getElementById("tickSpeedAmount").style.visibility = "hidden";
        document.getElementById("tickSpeedPurchases").style.visibility = "hidden";
        document.getElementById("fourthRow").style.display = "none";
        document.getElementById("fifthRow").style.display = "none";
        document.getElementById("sixthRow").style.display = "none";
        document.getElementById("seventhRow").style.display = "none";
        document.getElementById("eightRow").style.display = "none";
        showDimTab('antimatterdimensions')
        updateTickSpeed();
        updateDimensions();
        updateChallenges();
        updateAutobuyers();
    }
};


function breakInfinity() {
    if (player.autobuyers[11]%1 === 0 || player.autobuyers[11].interval>100) return false
    if (player.break && !player.currentChallenge.includes("post")) {
        player.break = false
        document.getElementById("break").textContent = "BREAK INFINITY"
    } else {
        player.break = true
        document.getElementById("break").textContent = "FIX INFINITY"
        giveAchievement("Limit Break")
    }
}
function galIP(){
    let gal = player.galaxies
    if (gal<5) return gal
    if (gal<50) return 2 + Math.pow(5+gal, 0.6)
    return Math.pow(gal,.4)+7
}

function getB60Mult(){
    let g = player.galaxies;
	if(player.infinityUpgrades.includes("postinfi70"))return Math.pow(2.2,g)
	if(player.achievements.includes("r96"))return Math.pow(2.5,g)
	if(player.achievements.includes("r96")&&player.infinityUpgrades.includes("postinfi70"))return Math.pow(2.8,g)
    return Math.pow(2,g)
}

function gainedInfinityPoints() {
    let div = 308;
	if (player.achievements.includes("r84")) div -= 4;
    if (player.achievements.includes("r85")) div -= 4;
    if (player.achievements.includes("r93")) div -= 4;
	if (player.achievements.includes("r103")) div -= 4;
	if (player.timestudy.studies.includes(111)) div -= 15;
    div -= galIP()
    var ret = Decimal.pow(10, player.money.e/div -0.75).times(getIPMult())
    if (!player.break || player.currentChallenge != "")ret = new Decimal(1).times(getIPMult());
    if (player.galacticSacrifice.upgrades.includes(45))ret=ret.times(galUpgrade45());
	if(player.galacticSacrifice.upgrades.includes(74))ret=ret.times(galUpgrade64());
    if (player.timestudy.studies.includes(41)) ret = ret.times(timeStudy41())
    if (player.timestudy.studies.includes(51)) ret = ret.times(1e15)
    if (player.timestudy.studies.includes(141)) ret = ret.times(new Decimal(1e45).dividedBy(Decimal.pow(15, Math.log(player.thisInfinityTime+1)*Math.pow(player.thisInfinityTime+1, 0.125))).max(1))
    if (player.timestudy.studies.includes(142)) ret = ret.times(1e25)
    if (player.timestudy.studies.includes(143)) ret = ret.times(Decimal.pow(15, Math.log(player.thisInfinityTime+1)*Math.pow(player.thisInfinityTime+1, 0.125)))
    if (player.achievements.includes("r116")) ret = ret.times(Decimal.pow(2, Math.log10(getInfinitied()+1)))
    if (player.achievements.includes("r125")) ret = ret.times(Decimal.pow(2, Math.log(player.thisInfinityTime+1)*Math.pow(player.thisInfinityTime+1, 0.11)))
    if (player.dilation.upgrades.includes(7)) ret = ret.times(player.dilation.dilatedTime.pow(1000))
    if (player.infinityUpgrades.includes("postinfi60")) ret = ret.times(getB60Mult())
    if (player.achievements.includes("r43")) ret = ret.times(100);
    if (player.achievements.includes("r55")) ret = ret.times(Math.max(Math.log10(6000/player.bestInfinityTime), 1));
    if (player.achievements.includes("r41")) ret = ret.times(Math.pow(Math.log10(player.spreadingCancer), .05)).times(2);
    if (player.achievements.includes("r51")) {
        let galaxies = player.galaxies
      	ret = ret.times(galaxies+1)
    }
    if (player.achievements.includes("r104")) ret = ret.times(2e25);
    if (player.achievements.includes("r106")) ret = ret.times(Decimal.pow(10,player.replicanti.galaxies));
	if (player.challenges.includes("postcngm4r_3")&&player.replicanti.unl) {
        ret=ret.times(Decimal.pow(player.replicanti.amount.add(1).log10(),5));
    }
    return ret.floor()
}

function EternitiesEPMult(){
	let eternitiedPower=player.eternities+1
	if(eternitiedPower>10)eternitiedPower=10*Math.log10(eternitiedPower);
	if(eternitiedPower>20)eternitiedPower=Math.sqrt(eternitiedPower*20);
	return Decimal.pow(3, eternitiedPower);
}

function gainedEternityPoints() {
	let div=308;
	var ret = Decimal.pow(5, player.infinityPoints.plus(gainedInfinityPoints()).e/div -0.7).times(player.epmult)
	let eternitiedPower=player.eternities+1
	if(eternitiedPower>10)eternitiedPower=10*Math.log10(eternitiedPower);
	if(eternitiedPower>20)eternitiedPower=Math.sqrt(eternitiedPower*20);
	ret=ret.times(Decimal.pow(3, eternitiedPower));
    if (player.galacticSacrifice.upgrades.includes(61)) ret = ret.times(galUpgrade61())
	if(player.timeless.upgrades.includes(4))ret=ret.mul(TLPU4());
	
  dilationstart = getDilationStart();
    if(ret.log10()>=dilationstart){
	  ret = Decimal.pow(10, Math.pow(ret.log10()/dilationstart, getDilationPower())*dilationstart)
	  if (player.dilation.active)ret = Decimal.pow(10, Math.pow(ret.log10()/dilationstart, getDilationPower())*dilationstart)
    }
	
    if (player.timestudy.studies.includes(61)) ret = ret.times(10)
    if (player.timestudy.studies.includes(121)) ret = ret.times(((253 - averageEp.dividedBy(player.epmult).dividedBy(10).min(248).max(3))/5)) //x300 if tryhard, ~x60 if not
    if (player.timestudy.studies.includes(122)) ret = ret.times(35)
    if (player.timestudy.studies.includes(123)) ret = ret.times(Math.sqrt(1.39*player.thisEternity/10))
    if (player.achievements.includes("r102")) ret = ret.times(player.eternities+1);
    if (player.achievements.includes("r107")) ret = ret.times(Decimal.pow(Math.log10(player.infinitied+10),0.5));
    if (player.achievements.includes("r108")) ret = ret.times(Decimal.pow(player.replicanti.amount.add(10).log10(),0.2));
	if (player.achievements.includes("r114")) ret = ret.times(Math.pow(10,ECTimesCompleted("eterc4")+ECTimesCompleted("eterc12")));
	if (player.eternityUpgrades.includes(8)) ret = ret.times(EU8Effect());
    return ret.floor()
}

function gainedEternityPointsBeforeDilation() {
	let div=308;
	var ret = Decimal.pow(5, player.infinityPoints.plus(gainedInfinityPoints()).e/div -0.7).times(player.epmult)
	let eternitiedPower=player.eternities+1
	if(eternitiedPower>10)eternitiedPower=10*Math.log10(eternitiedPower);
	if(eternitiedPower>20)eternitiedPower=Math.sqrt(eternitiedPower*20);
	ret=ret.times(Decimal.pow(3, eternitiedPower));
    if (player.galacticSacrifice.upgrades.includes(61)) ret = ret.times(galUpgrade61())
	if(player.timeless.upgrades.includes(4))ret=ret.mul(TLPU4());
	
    if (player.timestudy.studies.includes(61)) ret = ret.times(10)
    if (player.timestudy.studies.includes(121)) ret = ret.times(((253 - averageEp.dividedBy(player.epmult).dividedBy(10).min(248).max(3))/5)) //x300 if tryhard, ~x60 if not
    if (player.timestudy.studies.includes(122)) ret = ret.times(35)
    if (player.timestudy.studies.includes(123)) ret = ret.times(Math.sqrt(1.39*player.thisEternity/10))
    if (player.achievements.includes("r102")) ret = ret.times(player.eternities+1);
    if (player.achievements.includes("r107")) ret = ret.times(Decimal.pow(Math.log10(player.infinitied+10),0.5));
    if (player.achievements.includes("r108")) ret = ret.times(Decimal.pow(player.replicanti.amount.add(10).log10(),0.2));
	if (player.achievements.includes("r114")) ret = ret.times(Math.pow(10,ECTimesCompleted("eterc4")+ECTimesCompleted("eterc12")));
	if (player.eternityUpgrades.includes(8)) ret = ret.times(EU8Effect());
    return ret.floor()
}

function setAchieveTooltip() {
    var apocAchieve = document.getElementById("Antimatter Apocalypse");
    var noPointAchieve = document.getElementById("There's no point in doing that");
    var sanic = document.getElementById("Supersanic")
    var forgotAchieve = document.getElementById("I forgot to nerf that")
    var potato = document.getElementById("Faster than a potato")
    let potato2 = document.getElementById("Faster than a squared potato")
    let potato3 = document.getElementById("Faster than a potato^286078")
    var dimensional = document.getElementById("Multidimensional")
    var IPBelongs = document.getElementById("All your IP are belong to us")
    var reference = document.getElementById("Yet another infinity reference")
    let blink = document.getElementById("Blink of an eye")
    let exist = document.getElementById("This achievement doesn't exist")
    let exist2 = document.getElementById("This achievement doesn't exist II")
    let spare = document.getElementById("I got a few to spare")
    let speed = document.getElementById("Ludicrous Speed")
    let speed2 = document.getElementById("I brake for nobody")
    let overdrive = document.getElementById("MAXIMUM OVERDRIVE")
    let minute = document.getElementById("Minute of infinity")
    let infiniteIP = document.getElementById("Can you get infinite IP?")
    let over9000 = document.getElementById("IT'S OVER 9000")
    let dawg = document.getElementById("Yo dawg, I heard you liked infinities...")
    let eatass = document.getElementById("Like feasting on a behind")
    let layer = document.getElementById("But I wanted another prestige layer...")
    let layer2 = document.getElementById("But I wanted another prestige layer again...")
    let fkoff = document.getElementById("What do I have to do to get rid of you")
    let minaj = document.getElementById("Popular music")
    let infstuff = document.getElementById("I never liked this infinity stuff anyway")
    let when = document.getElementById("When will it be enough?")
    let thinking = document.getElementById("Now you're thinking with dilation!")
    let thisis = document.getElementById("This is what I have to do to get rid of you.")

    apocAchieve.setAttribute('ach-tooltip', "Get over " + formatValue(player.options.notation, 1e80, 0, 0) + " antimatter.");
    noPointAchieve.setAttribute('ach-tooltip', "Buy a single First Dimension when you have over " + formatValue(player.options.notation, 1e150, 0, 0) + " of them. Reward: First Dimensions are 10% stronger and you can max buy Dimension and Tickspeed Boosts.");
    forgotAchieve.setAttribute('ach-tooltip', "Get any Dimension multiplier over " + formatValue(player.options.notation, 1e31, 0, 0) + ". Reward: First Dimensions are 5% stronger and multiplier to ND based on product of all dims.");
    sanic.setAttribute('ach-tooltip', "Have antimatter/sec exceed your current antimatter above " + formatValue(player.options.notation, 1e63, 0, 0));
    potato.setAttribute('ach-tooltip', "Get more than " + formatValue(player.options.notation, 1e29, 0, 0) + " ticks per second. Reward: Reduces starting tick interval by 2%.");
    potato2.setAttribute('ach-tooltip', "Get more than " + formatValue(player.options.notation, 1e58, 0, 0) + " ticks per second. Reward: Reduces starting tick interval by 2%, and Tickspeed boost Infinity Dimensions at a very reduced rate.");
    potato3.setAttribute('ach-tooltip', "Get more than "+shortenCosts(new Decimal("1e8296262"))+" ticks per second.")
    dimensional.setAttribute('ach-tooltip', "Reach " + formatValue(player.options.notation, 1e12, 0, 0) + " of all dimensions except 8th.");
    IPBelongs.setAttribute('ach-tooltip', "Big Crunch for "+shortenCosts(1e150)+" IP. Reward: IP gain formula is better, and unlock new Break Infinity Upgrades.")
    reference.setAttribute('ach-tooltip', "Get a x"+shortenDimensions(Number.MAX_VALUE)+" multiplier in a single sacrifice. Reward: Sacrifices are stronger.")
    blink.setAttribute('ach-tooltip', "Get to Infinity in under 200 milliseconds. Reward: Start with " + formatValue(player.options.notation, 1e25, 0, 0) + " antimatter and all dimensions are stronger in first 300ms of Infinity.");
    spare.setAttribute('ach-tooltip', "Reach " +formatValue(player.options.notation, new Decimal("1e9500"), 0, 0)+" antimatter. Reward: Dimensions are more powerful the more unspent antimatter you have, and IP gain formula is better.");
    //exist.setAttribute('ach-tooltip', "Reach " + formatValue(player.options.notation, 9.9999e9999, 0, 0) + " antimatter. Reward: Dimensions are more powerful the more unspent antimatter you have."); (i like the 9 9s thing and no one will see it with a formatted value)
    //exist2.setAttribute('ach-tooltip', "Reach " + formatValue(player.options.notation, 1e35000, 0, 0) + " antimatter. Reward: Dimensions are more powerful the more unspent antimatter you have.")
    speed.setAttribute('ach-tooltip', "Big Crunch for "+shortenCosts(1e200)+" IP in 2 seconds or less. Reward: All dimensions are significantly stronger in first 5 seconds of infinity, and gain an Eternity Point.")
    speed2.setAttribute('ach-tooltip', "Big Crunch for "+shortenCosts(1e250)+" IP in 20 seconds or less. Reward: All dimensions are significantly stronger in first 60 seconds of infinity, and gain an Eternity Point.")
    overdrive.setAttribute('ach-tooltip', "Big Crunch with " + shortenCosts(1e300) + " IP/min. Reward: IP gain formula is better.")
    minute.setAttribute('ach-tooltip', "Reach " + shortenCosts(1e260) + " infinity power. Reward: Double infinity power gain.")
    infiniteIP.setAttribute('ach-tooltip', "Reach "+shortenCosts(new Decimal("1e30008"))+" IP.")
    over9000.setAttribute('ach-tooltip', "Get a total sacrifice multiplier of "+shortenCosts(new Decimal("1e9000"))+". Reward: Sacrifice doesn't reset your dimensions.")
    dawg.setAttribute('ach-tooltip', "Have all your past 10 infinities be at least "+shortenMoney(Number.MAX_VALUE)+" times higher IP than the previous one. Reward: Your antimatter doesn't reset on dimboost/galaxy.")
    eatass.setAttribute('ach-tooltip', "Reach "+shortenCosts(1e100)+" IP without any infinities or first dimensions. Reward: IP multiplier based on time spent this infinity.")
    layer.setAttribute('ach-tooltip', "Reach "+shortenMoney(Number.MAX_VALUE)+" EP. Reward: [TBD] Unlock Interreality, the 'another prestige layer'.")
    layer2.setAttribute('ach-tooltip', "[TBD] Reach "+shortenMoney(Number.MAX_VALUE)+" Interreality points.")
    fkoff.setAttribute('ach-tooltip', "Reach "+shortenCosts(new Decimal("1e22000"))+" IP without any time studies. Reward: Time dimensions are multiplied by the number of studies you have (post-dilation).")
    minaj.setAttribute('ach-tooltip', "Have 180 times more non-bonus replicanti galaxies than normal galaxies. Reward: Replicanti galaxies divide your replicanti by "+shortenMoney(Number.MAX_VALUE)+" instead of resetting them to 1.")
    infstuff.setAttribute('ach-tooltip', "Reach "+shortenCosts(new Decimal("1e140000"))+" IP without buying IDs or IP multipliers. Reward: You start eternities with all Infinity Challenges unlocked and completed.")
    when.setAttribute('ach-tooltip', "Reach "+shortenCosts( new Decimal("1e20000"))+" replicanti. Reward: You gain replicanti 2 times faster under "+shortenMoney(Number.MAX_VALUE)+" replicanti, and 8 times faster above "+shortenMoney(Number.MAX_VALUE)+" replicanti.")
    thinking.setAttribute('ach-tooltip', "Eternity for "+shortenCosts( new Decimal("1e600"))+" EP in 1 minute or less while dilated. Reward: Achievement Power affects DT Production at a reduced rate (pre-dilation).")
    thisis.setAttribute('ach-tooltip', "Reach "+shortenCosts(new Decimal('1e20000'))+" IP without any time studies while dilated.")
    document.getElementById("Limit Break").setAttribute('ach-tooltip', "Break Infinity. Reward: Multiplier to IP gain based on galaxies (galaxies+1), each tickspeed upgrade multiply your tickrate by 1.001 (this isn't affected by galaxies), third dilation threshold is multiplied by "+shortenCosts(1e15)+", and unlock Eternity tab.")
}

document.getElementById("notation").onclick = function () {
    player.options.scientific = !player.options.scientific;
    if (player.options.notation === "Infinity") {
        player.options.notation = "Scientific";
        document.getElementById("notation").textContent = ("Notation: Scientific")
    } else if (player.options.notation === "Scientific") {
        player.options.notation = "Engineering";
        document.getElementById("notation").textContent = ("Notation: Engineering")
    } else if (player.options.notation === "Engineering") {
        player.options.notation = "Letters";
        document.getElementById("notation").textContent = ("Notation: Letters")
    } else if (player.options.notation === "Letters") {
        player.options.notation = "Standard";
        document.getElementById("notation").textContent = ("Notation: Standard")
    } else if (player.options.notation === "Standard") {
        player.options.notation = "Emojis";
        document.getElementById("notation").textContent = ("Notation: Cancer")
    } else if (player.options.notation === "Emojis") {
        player.options.notation = "Mixed scientific";
        document.getElementById("notation").textContent = ("Notation: Mixed scientific")
    } else if (player.options.notation === "Mixed scientific") {
        player.options.notation = "Mixed engineering";
        document.getElementById("notation").textContent = ("Notation: Mixed engineering")
    } else if (player.options.notation === "Mixed engineering") {
        player.options.notation = "Logarithm";
        document.getElementById("notation").textContent = ("Notation: Logarithm")
    } else if (player.options.notation === "Logarithm") {
        player.options.notation = "Brackets";
        document.getElementById("notation").textContent = ("Notation: Brackets")
    } else if (player.options.notation === "Brackets") {
      player.options.notation = "Infinity";
      document.getElementById("notation").textContent = ("Notation: Infinity")
    }

    updateLastTenRuns();
    updateLastTenEternities();
    updateTickSpeed();
    setAchieveTooltip();
    updateCosts();
    updateDilationUpgradeCosts()
    document.getElementById("epmult").innerHTML = "You gain 5 times more EP<p>Currently: "+shortenDimensions(player.epmult)+"x<p>Cost: "+shortenDimensions(player.epmultCost)+" EP"
};


document.getElementById("newsbtn").onclick = function() {
  if (!player.options.newsHidden) {
    document.getElementById("game").style.display = "none";
    player.options.newsHidden = true
  } else {
    document.getElementById("game").style.display = "block";
    player.options.newsHidden = false
    scrollNextMessage()
  }
}


function resetDimensions() {
    var tiers = [ null, "first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eight" ];

    for (i = 1; i <= 8; i++) {
        player[tiers[i] + "Amount"] = new Decimal(0)
        player[tiers[i] + "Pow"] = new Decimal(1)
    }
    player.firstCost = new Decimal(10)
    player.secondCost = new Decimal(100)
    player.thirdCost = new Decimal(10000)
    player.fourthCost = new Decimal(1e6)
    player.fifthCost = new Decimal(1e9)
    player.sixthCost = new Decimal(1e13)
    player.seventhCost = new Decimal(1e18)
    player.eightCost = new Decimal(1e24)
    player.eightPow = new Decimal(player.chall11Pow)

    decreaseDimCosts();
}

function calcSacrificeBoost() {
    if (player.firstAmount == 0) return new Decimal(1);
    if (player.challenges.includes("postc5")) {
		let power=0.01
		if (player.achievements.includes("r88"))power += 0.001
		if (player.infinityUpgrades.includes("postinfi73"))power += 0.001
        if (player.timestudy.studies.includes(228)) power += 0.002
        return player.firstAmount.dividedBy(player.sacrificed.max(1)).pow(power).max(1)
    }
    if (player.currentChallenge != "challenge11") {
        var sacrificePow=2;
        if (player.achievements.includes("r32")) sacrificePow += 0.2;
        if (player.achievements.includes("r57")) sacrificePow += 0.2; //this upgrade was too OP lol
        return Decimal.pow((player.firstAmount.e/10.0), sacrificePow).dividedBy(((Decimal.max(player.sacrificed.e, 1)).dividedBy(10.0)).pow(sacrificePow).max(1)).max(1);
    } else {
        return player.firstAmount.pow(0.05).dividedBy(player.sacrificed.pow(0.04).max(1)).max(1);
    }
}

function calcTotalSacrificeBoost() {
    if (player.sacrificed == 0) return new Decimal(1);
    if (player.challenges.includes("postc5")) {
		let power=0.01
		if (player.achievements.includes("r88"))power += 0.001
		if (player.infinityUpgrades.includes("postinfi73"))power += 0.001
        if (player.timestudy.studies.includes(228)) power += 0.002
        return player.sacrificed.pow(power).max(1)
    }
    if (player.currentChallenge != "challenge11") {
        var sacrificePow=2;
        if (player.achievements.includes("r32")) sacrificePow += 0.2;
        if (player.achievements.includes("r57")) sacrificePow += 0.2;
        return Decimal.pow((player.sacrificed.e/10.0), sacrificePow);
    } else {
        return player.sacrificed.pow(0.05) //this is actually off but like im not sure how youd make it good. not that it matters.
    }
}


function sacrifice(auto = false) {
    if (player.eightAmount == 0) return false;
    if (player.resets < 5) return false
    if (player.currentEternityChall == "eterc3") return false
    if (player.currentChallenge == "postcngm4r_1") return false
    if (player.currentChallenge == "challenge11" && (calcTotalSacrificeBoost().gte(new Decimal('1e8888')) || player.chall11Pow.gte(new Decimal('1e8888')))) return false
    if (!auto) floatText("eightD", "x" + shortenMoney(calcSacrificeBoost()))
    if (calcSacrificeBoost().gte(Number.MAX_VALUE) && player.currentChallenge !== 'challenge11') giveAchievement("Yet another infinity reference");
    player.eightPow = player.eightPow.times(calcSacrificeBoost())
    player.sacrificed = player.sacrificed.plus(player.firstAmount);
    if (player.currentChallenge != "challenge11") {
        if ((player.currentChallenge == "challenge7" || player.currentChallenge == "postcngm3_3") && !player.achievements.includes("r118")) clearDimensions(6);
        else if (!player.achievements.includes("r118")) clearDimensions(7);
    } else {
        player.chall11Pow = player.chall11Pow.times(calcSacrificeBoost())
        if (!player.achievements.includes("r118")) resetDimensions();
        player.money = new Decimal(100)

    }
    if (calcTotalSacrificeBoost() >= 600) giveAchievement("The Gods are pleased");
    if (calcTotalSacrificeBoost().gte("1e9000") && player.currentChallenge !== "challenge11") giveAchievement("IT'S OVER 9000");
}




document.getElementById("sacrifice").onclick = function () {
    if (!document.getElementById("confirmation").checked) {
        if (!confirm("Dimensional Sacrifice will remove all of your first to seventh dimensions (with the cost and multiplier unchanged) for a boost to Eighth Dimension. It will take time to regain production.")) {
            return false;
        }
    }

    auto = false;
    return sacrifice();
}

document.getElementById("gSacrifice").onclick = function () {
    if (getGSAmount().lt(1)) return false
    if (!document.getElementById("gConfirmation").checked) {
        if (!confirm("Galactic Sacrifice will do a galaxy reset, and then remove all of your galaxies, in exchange of galaxy points which can be use to buy many overpowered upgrades, but it will take a lot of time to recover, are you sure you wanna do this?")) {
            return false;
        }
    }

    return galacticSacrifice();
}


document.getElementById("sacrificebtn").onclick = function () {
    if (getGSAmount().lt(1)) return false
    if (!document.getElementById("gConfirmation").checked) {
        if (!confirm("Galactic Sacrifice will do a galaxy reset, and then remove all of your galaxies, in exchange of galaxy points which can be use to buy many overpowered upgrades, but it will take a lot of time to recover, are you sure you wanna do this?")) {
            return false;
        }
    }

    return galacticSacrifice();
}

function updateAutobuyers() {
    var autoBuyerDim1 = new Autobuyer (1)
    var autoBuyerDim2 = new Autobuyer (2)
    var autoBuyerDim3 = new Autobuyer (3)
    var autoBuyerDim4 = new Autobuyer (4)
    var autoBuyerDim5 = new Autobuyer (5)
    var autoBuyerDim6 = new Autobuyer (6)
    var autoBuyerDim7 = new Autobuyer (7)
    var autoBuyerDim8 = new Autobuyer (8)
    var autoBuyerDimBoost = new Autobuyer (9)
    var autoBuyerGalaxy = new Autobuyer (document.getElementById("secondSoftReset"))
    var autoBuyerTickspeed = new Autobuyer (document.getElementById("tickSpeed"))
    var autoBuyerInf = new Autobuyer (document.getElementById("bigcrunch"))
    var autoSacrifice = new Autobuyer(13)
    var autoGalSacrifice = new Autobuyer(14)


    autoBuyerDim1.interval = 1500
    autoBuyerDim2.interval = 2000
    autoBuyerDim3.interval = 2500
    autoBuyerDim4.interval = 3000
    autoBuyerDim5.interval = 4000
    autoBuyerDim6.interval = 5000
    autoBuyerDim7.interval = 6000
    autoBuyerDim8.interval = 7500
    autoBuyerDimBoost.interval = 8000
    autoBuyerGalaxy.interval = 60000
    autoBuyerTickspeed.interval = 5000
    autoBuyerInf.interval = 60000

    autoSacrifice.interval = 15000
    autoSacrifice.priority = 5

    autoGalSacrifice.interval = 15000
    autoGalSacrifice.priority = 5

    autoBuyerDim1.tier = 1
    autoBuyerDim2.tier = 2
    autoBuyerDim3.tier = 3
    autoBuyerDim4.tier = 4
    autoBuyerDim5.tier = 5
    autoBuyerDim6.tier = 6
    autoBuyerDim7.tier = 7
    autoBuyerDim8.tier = 8
    autoBuyerTickSpeed.tier = 9

    if (player.challenges.includes("challenge1") && player.autobuyers[0] == 1) {
        player.autobuyers[0] = autoBuyerDim1
        document.getElementById("autoBuyer1").style.display = "inline-block"
    }
    if (player.challenges.includes("challenge2") && player.autobuyers[1] == 2) {
        player.autobuyers[1] = autoBuyerDim2
        document.getElementById("autoBuyer2").style.display = "inline-block"
    }
    if (player.challenges.includes("challenge3") && player.autobuyers[2] == 3) {
        player.autobuyers[2] = autoBuyerDim3
        document.getElementById("autoBuyer3").style.display = "inline-block"
    }
    if (player.challenges.includes("challenge4") && player.autobuyers[9] == 10) {
        player.autobuyers[9] = autoBuyerDimBoost
        document.getElementById("autoBuyerDimBoost").style.display = "inline-block"
    }
    if (player.challenges.includes("challenge5") && player.autobuyers[8] == 9) {
        player.autobuyers[8] = autoBuyerTickspeed
        document.getElementById("autoBuyerTickSpeed").style.display = "inline-block"
    }
    if (player.challenges.includes("challenge6") && player.autobuyers[4] == 5) {
        player.autobuyers[4] = autoBuyerDim5
        document.getElementById("autoBuyer5").style.display = "inline-block"
    }
    if (player.challenges.includes("challenge7") && player.autobuyers[11] == 12) {
        player.autobuyers[11] = autoBuyerInf
        document.getElementById("autoBuyerInf").style.display = "inline-block"
    }
    if (player.challenges.includes("challenge8") && player.autobuyers[3] == 4) {
        player.autobuyers[3] = autoBuyerDim4
        document.getElementById("autoBuyer4").style.display = "inline-block"
    }
    if (player.challenges.includes("challenge9") && player.autobuyers[6] == 7) {
        player.autobuyers[6] = autoBuyerDim7
        document.getElementById("autoBuyer7").style.display = "inline-block"
    }
    if (player.challenges.includes("challenge10") && player.autobuyers[5] == 6) {
        player.autobuyers[5] = autoBuyerDim6
        document.getElementById("autoBuyer6").style.display = "inline-block"
    }
    if (player.challenges.includes("challenge11") && player.autobuyers[7] == 8) {
        player.autobuyers[7] = autoBuyerDim8
        document.getElementById("autoBuyer8").style.display = "inline-block"
    }
    if (player.challenges.includes("challenge12") && player.autobuyers[10] == 11) {
        player.autobuyers[10] = autoBuyerGalaxy
        document.getElementById("autoBuyerGalaxies").style.display = "inline-block"
    }

    if (player.challenges.includes("challenge13") && player.autobuyers[12] == 13) {
        player.autobuyers[12] = autoSacrifice
        document.getElementById("autoBuyerSac").style.display = "inline-block"
    } else {
        document.getElementById("autoBuyerSac").style.display = "none"
    }

    if (player.challenges.includes("challenge14") && player.autobuyers[13] == 14) {
        player.autobuyers[13] = autoGalSacrifice
        document.getElementById("autoBuyerGalSac").style.display = "inline-block"
    } else {
        document.getElementById("autoBuyerGalSac").style.display = "none"
    }

    if (player.eternities < 100) {
        document.getElementById("autoBuyerEter").style.display = "none"
    }

    if (player.infinityUpgrades.includes("autoBuyerUpgrade")) {
        document.getElementById("interval1").textContent = "Current interval: " + (player.autobuyers[0].interval/2000).toFixed(2) + " seconds"
        document.getElementById("interval2").textContent = "Current interval: " + (player.autobuyers[1].interval/2000).toFixed(2) + " seconds"
        document.getElementById("interval3").textContent = "Current interval: " + (player.autobuyers[2].interval/2000).toFixed(2) + " seconds"
        document.getElementById("interval4").textContent = "Current interval: " + (player.autobuyers[3].interval/2000).toFixed(2) + " seconds"
        document.getElementById("interval5").textContent = "Current interval: " + (player.autobuyers[4].interval/2000).toFixed(2) + " seconds"
        document.getElementById("interval6").textContent = "Current interval: " + (player.autobuyers[5].interval/2000).toFixed(2) + " seconds"
        document.getElementById("interval7").textContent = "Current interval: " + (player.autobuyers[6].interval/2000).toFixed(2) + " seconds"
        document.getElementById("interval8").textContent = "Current interval: " + (player.autobuyers[7].interval/2000).toFixed(2) + " seconds"
        document.getElementById("intervalTickSpeed").textContent = "Current interval: " + (player.autobuyers[8].interval/2000).toFixed(2) + " seconds"
        document.getElementById("intervalDimBoost").textContent = "Current interval: " + (player.autobuyers[9].interval/2000).toFixed(2) + " seconds"
        document.getElementById("intervalGalaxies").textContent = "Current interval: " + (player.autobuyers[10].interval/2000).toFixed(2) + " seconds"
        document.getElementById("intervalInf").textContent = "Current interval: " + (player.autobuyers[11].interval/2000).toFixed(2) + " seconds"
        document.getElementById("intervalSac").textContent = "Current interval: " + (player.autobuyers[12].interval/2000).toFixed(2) + " seconds"
        document.getElementById("intervalGalSac").textContent = "Current interval: " + (player.autobuyers[13].interval/2000).toFixed(2) + " seconds"
    } else {
        document.getElementById("interval1").textContent = "Current interval: " + (player.autobuyers[0].interval/1000).toFixed(2) + " seconds"
        document.getElementById("interval2").textContent = "Current interval: " + (player.autobuyers[1].interval/1000).toFixed(2) + " seconds"
        document.getElementById("interval3").textContent = "Current interval: " + (player.autobuyers[2].interval/1000).toFixed(2) + " seconds"
        document.getElementById("interval4").textContent = "Current interval: " + (player.autobuyers[3].interval/1000).toFixed(2) + " seconds"
        document.getElementById("interval5").textContent = "Current interval: " + (player.autobuyers[4].interval/1000).toFixed(2) + " seconds"
        document.getElementById("interval6").textContent = "Current interval: " + (player.autobuyers[5].interval/1000).toFixed(2) + " seconds"
        document.getElementById("interval7").textContent = "Current interval: " + (player.autobuyers[6].interval/1000).toFixed(2) + " seconds"
        document.getElementById("interval8").textContent = "Current interval: " + (player.autobuyers[7].interval/1000).toFixed(2) + " seconds"
        document.getElementById("intervalTickSpeed").textContent = "Current interval: " + (player.autobuyers[8].interval/1000).toFixed(2) + " seconds"
        document.getElementById("intervalDimBoost").textContent = "Current interval: " + (player.autobuyers[9].interval/1000).toFixed(2) + " seconds"
        document.getElementById("intervalGalaxies").textContent = "Current interval: " + (player.autobuyers[10].interval/1000).toFixed(2) + " seconds"
        document.getElementById("intervalInf").textContent = "Current interval: " + (player.autobuyers[11].interval/1000).toFixed(2) + " seconds"
        document.getElementById("intervalSac").textContent = "Current interval: " + (player.autobuyers[12].interval/1000).toFixed(2) + " seconds"
        document.getElementById("intervalGalSac").textContent = "Current interval: " + (player.autobuyers[13].interval/1000).toFixed(2) + " seconds"
    }

    var maxedAutobuy = 0;
    var e100autobuy = 0;
    for (let tier = 1; tier <= 8; ++tier) {
    document.getElementById("toggleBtn" + tier).style.display = "inline-block";
        if (player.autobuyers[tier-1].bulk >= 1e100) {
        player.autobuyers[tier-1].bulk = 1e100;
        document.getElementById("buyerBtn" + tier).textContent = shortenDimensions(player.autobuyers[tier-1].bulk)+"x bulk purchase";
        e100autobuy++;
        }
        else {
        if (player.autobuyers[tier-1].interval <= 100) {
            if (player.autobuyers[tier-1].bulk * 2 >= 1e100) {
                document.getElementById("buyerBtn" + tier).innerHTML = shortenDimensions(1e100)+"x bulk purchase<br>Cost: " + shortenDimensions(player.autobuyers[tier-1].cost) + " IP";
            }
            else {
                document.getElementById("buyerBtn" + tier).innerHTML = shortenDimensions(player.autobuyers[tier-1].bulk*2)+"x bulk purchase<br>Cost: " + shortenDimensions(player.autobuyers[tier-1].cost) + " IP";
            }
            maxedAutobuy++;
        }
        else document.getElementById("buyerBtn" + tier).innerHTML = "40% smaller interval <br>Cost: " + shortenDimensions(player.autobuyers[tier-1].cost) + " IP"
        }
    }

    if (player.autobuyers[8].interval <= 100) {
        document.getElementById("buyerBtnTickSpeed").style.display = "none"
        document.getElementById("toggleBtnTickSpeed").style.display = "inline-block"
        maxedAutobuy++;
    }
    if (player.autobuyers[9].interval <= 100) {
        document.getElementById("buyerBtnDimBoost").style.display = "none"
        maxedAutobuy++;
    }
    if (player.autobuyers[10].interval <= 100) {
        document.getElementById("buyerBtnGalaxies").style.display = "none"
        maxedAutobuy++;
    }
    if (player.autobuyers[11].interval <= 100) {
        document.getElementById("buyerBtnInf").style.display = "none"
        maxedAutobuy++;
    }
    if (player.autobuyers[12].interval <= 100) {
        document.getElementById("buyerBtnSac").style.display = "none"
        maxedAutobuy++;
    }
    if (player.autobuyers[13].interval <= 100) {
        document.getElementById("buyerBtnGalSac").style.display = "none"
        maxedAutobuy++;
    }

    if (maxedAutobuy >= 9) giveAchievement("Age of Automation");
    if (maxedAutobuy >= 14) giveAchievement("Definitely not worth it");
    if (e100autobuy >= 8) giveAchievement("Professional bodybuilder");

    document.getElementById("buyerBtnTickSpeed").innerHTML = "40% smaller interval <br>Cost: " + player.autobuyers[8].cost + " IP"
    document.getElementById("buyerBtnDimBoost").innerHTML = "40% smaller interval <br>Cost: " + player.autobuyers[9].cost + " IP"
    document.getElementById("buyerBtnGalaxies").innerHTML = "40% smaller interval <br>Cost: " + player.autobuyers[10].cost + " IP"
    document.getElementById("buyerBtnInf").innerHTML = "40% smaller interval <br>Cost: " + player.autobuyers[11].cost + " IP"
    document.getElementById("buyerBtnSac").innerHTML = "40% smaller interval <br>Cost: " + player.autobuyers[12].cost + " IP"
    document.getElementById("buyerBtnGalSac").innerHTML = "40% smaller interval <br>Cost: " + player.autobuyers[13].cost + " IP"


    for (var i=0; i<8; i++) {
        if (player.autobuyers[i]%1 !== 0) document.getElementById("autoBuyer"+(i+1)).style.display = "inline-block"
    }
    if (player.autobuyers[8]%1 !== 0) document.getElementById("autoBuyerTickSpeed").style.display = "inline-block"
    if (player.autobuyers[9]%1 !== 0) document.getElementById("autoBuyerDimBoost").style.display = "inline-block"
    if (player.autobuyers[10]%1 !== 0) document.getElementById("autoBuyerGalaxies").style.display = "inline-block"
    if (player.autobuyers[11]%1 !== 0) document.getElementById("autoBuyerInf").style.display = "inline-block"
    if (player.autobuyers[12]%1 !== 0) document.getElementById("autoBuyerSac").style.display = "inline-block"
    if (player.autobuyers[13]%1 !== 0) document.getElementById("autoBuyerGalSac").style.display = "inline-block"

    for (var i=1; i<=14; i++) {
        player.autobuyers[i-1].isOn = document.getElementById(i + "ison").checked;
    }

    player.eternityBuyer.isOn = document.getElementById("eternityison").checked
    priorityOrder()
}


function autoBuyerArray() {
    var tempArray = []
    for (var i=0; i<player.autobuyers.length && i<9; i++) {
        if (player.autobuyers[i]%1 !== 0 ) {
            tempArray.push(player.autobuyers[i])
        }
    }
    return tempArray;
}


var priority = []


function priorityOrder() {
    var tempArray = []
    var i = 1;
    while(tempArray.length != autoBuyerArray().length) {

        for (var x=0 ; x< autoBuyerArray().length; x++) {
            if (autoBuyerArray()[x].priority == i) tempArray.push(autoBuyerArray()[x])
        }
        i++;
    }
    priority = tempArray;
}

function fromValue(value) {
  value = value.replace(/,/g, '')
  if (value.toUpperCase().split("E").length > 2 && value.split(" ")[0] !== value) {
      var temp = new Decimal(0)
      temp.mantissa = parseFloat(value.toUpperCase().split("E")[0])
      temp.exponent = parseFloat(value.toUpperCase().split("E")[1]+"e"+value.toUpperCase().split("E")[2])
      value = temp.toString()
  }
  if (value.includes(" ")) {
    const prefixes = [['', 'U', 'D', 'T', 'Qa', 'Qt', 'Sx', 'Sp', 'O', 'N'],
    ['', 'Dc', 'Vg', 'Tg', 'Qd', 'Qi', 'Se', 'St', 'Og', 'Nn'],
    ['', 'Ce', 'Dn', 'Tc', 'Qe', 'Qu', 'Sc', 'Si', 'Oe', 'Ne']]
    const prefixes2 = ['', 'MI', 'MC', 'NA', 'PC', 'FM', ' ']
    let e = 0;
    let m,k,l;
    if (value.split(" ")[1].length < 5) {
        for (l=101;l>0;l--) {
            if (value.includes(FormatList[l])) {
                e += l*3
                console.log("caught!"+l)

                break
            }
        }
        return Decimal.fromMantissaExponent(parseInt(value.split(" ")[0]), e)
    }
    for (let i=1;i<5;i++) {
        if (value.includes(prefixes2[i])) {
            m = value.split(prefixes2[i])[1]
            for (k=0;k<3;k++) {
                for (l=1;l<10;l++) {
                    if (m.includes(prefixes[k][l])) break;
                }
                if (l != 10) e += Math.pow(10,k)*l;
            }
            break;
        }
        return Decimal.fromMantissaExponent(value.split, e*3)
    }
    for (let i=1;i<=5;i++) {
        if (value.includes(prefixes2[i])) {
            for (let j=1;j+i<6;j++) {
                if (value.includes(prefixes2[i+j])) {
                    m=value.split(prefixes2[i+j])[1].split(prefixes2[i])[0]
                    if (m == "") e += Math.pow(1000,i);
                    else {
                        for (k=0;k<3;k++) {
                            for (l=1;l<10;l++) {
                                if (m.includes(prefixes[k][l])) break;
                            }
                            if (l != 10) e += Math.pow(10,k+i*3)*l;
                        }
                    }
                    break;
                }
            }
        }
    }
    return Decimal.fromMantissaExponent(parseFloat(value), i*3+3)
    //return parseFloat(value) + "e" + (e*3+3)
  }
  if (!isFinite(parseFloat(value[value.length-1]))) { //needs testing
    const l = " abcdefghijklmnopqrstuvwxyz"
    const v = value.replace(parseFloat(value),"")
    let e = 0;
    for (let i=0;i<v.length;i++) {
        for (let j=1;j<27;j++) {
            if (v[i] == l[j]) e += Math.pow(26,v.length-i-1)*j
        }
    }
    return Decimal.fromMantissaExponent(parseFloat(value), e*3)
    //return parseFloat(value) + "e" + (e*3)
  }
  value = value.replace(',','')
  if (value.split("e")[0] === "") return Decimal.fromMantissaExponent(Math.pow(10,parseFloat(value.split("e")[1])%1), parseInt(value.split("e")[1]))
  return Decimal.fromString(value)
}

function updatePriorities() {
    auto = false;
    for (var x=0 ; x < autoBuyerArray().length; x++) {
        if (x < 9) autoBuyerArray()[x].priority = parseInt(document.getElementById("priority" + (x+1)).value)
    }
    if (parseInt(document.getElementById("priority10").value) === 69
    || parseInt(document.getElementById("priority11").value) === 69
    || parseInt(fromValue(document.getElementById("priority12").value).toString()) === 69
    || parseInt(document.getElementById("bulkDimboost").value) === 69
    || parseInt(document.getElementById("overGalaxies").value) === 69
    || parseInt(document.getElementById("bulkgalaxy").value) === 69
    || parseInt(fromValue(document.getElementById("priority13").value).toString()) === 69
    || parseInt(fromValue(document.getElementById("priority14").value).toString()) === 69
    || parseInt(fromValue(document.getElementById("priority15").value).toString()) === 69) giveAchievement("Nice.");
    player.autobuyers[9].priority = parseInt(document.getElementById("priority10").value)
    player.autobuyers[10].priority = parseInt(document.getElementById("priority11").value)
    player.autobuyers[11].priority = fromValue(document.getElementById("priority12").value)
    if (!player.achievements.includes("r28")) {
        var bulk = Math.floor(Math.max(parseFloat(document.getElementById("bulkDimboost").value), 1))
    } else {
        var bulk = Math.max(parseFloat(document.getElementById("bulkDimboost").value), 0.05)
    }
    player.autobuyers[9].bulk = (isNaN(bulk)) ? 1 : bulk
    player.overXGalaxies = parseInt(document.getElementById("overGalaxies").value)
    player.autobuyers[12].priority = fromValue(document.getElementById("priority13").value)
    if (isNaN(player.autobuyers[12].priority) || player.autobuyers[12].priority === null || player.autobuyers[12].priority === undefined || player.autobuyers[12].priority <= 1) player.autobuyers[12].priority = Decimal.fromNumber(1.01)
    player.autobuyers[13].priority = fromValue(document.getElementById("priority14").value)
    if (isNaN(player.autobuyers[13].priority) || player.autobuyers[13].priority === null || player.autobuyers[13].priority === undefined || player.autobuyers[13].priority <= 1) player.autobuyers[13].priority = Decimal.fromNumber(1)
    player.autobuyers[10].bulk = parseFloat(document.getElementById("bulkgalaxy").value)
    const eterValue = fromValue(document.getElementById("priority15").value)
    if (!isNaN(eterValue)) player.eternityBuyer.limit = eterValue

    priorityOrder()
}

function updateCheckBoxes() {
    for (var i = 0; i < 14; i++) {
        if (player.autobuyers[i] && player.autobuyers[i]%1 !== 0) {
            if (player.autobuyers[i].isOn) document.getElementById((i+1) + "ison").checked = "true";
            else document.getElementById((i+1) + "ison").checked = ""
        }
    }
    document.getElementById("eternityison").checked = player.eternityBuyer.isOn

}


function toggleAutoBuyers() {
    var bool = player.autobuyers[0].isOn
    for (var i = 0; i<14; i++) {
        if (player.autobuyers[i]%1 !== 0) {
            player.autobuyers[i].isOn = !bool
        }
    }
    player.eternityBuyer.isOn = !bool
    updateCheckBoxes()
    updateAutobuyers()
}

function toggleBulk() {

    if (player.options.bulkOn) {
        player.options.bulkOn = false
        document.getElementById("togglebulk").textContent = "Enable bulk buy"
    } else {
        player.options.bulkOn = true
        document.getElementById("togglebulk").textContent = "Disable bulk buy"
    }
}

function toggleHotkeys() {
    if (player.options.hotkeys) {
        player.options.hotkeys = false
        document.getElementById("hotkeys").textContent = "Enable hotkeys"
    } else {
        player.options.hotkeys = true
        document.getElementById("hotkeys").textContent = "Disable hotkeys"
    }
}








function updateChallengeTimes() {
document.getElementById("challengetime2").textContent = "Challenge  " + 2 + " time record: " + timeDisplayShort(player.challengeTimes[0])
    document.getElementById("challengetime3").textContent = "Challenge  " + 3 + " time record: " + timeDisplayShort(player.challengeTimes[1])
    document.getElementById("challengetime4").textContent = "Challenge  " + 4 + " time record: " + timeDisplayShort(player.challengeTimes[6])
    document.getElementById("challengetime5").textContent = "Challenge  " + 5 + " time record: " + timeDisplayShort(player.challengeTimes[4])
    document.getElementById("challengetime6").textContent = "Challenge  " + 6 + " time record: " + timeDisplayShort(player.challengeTimes[8])
    document.getElementById("challengetime7").textContent = "Challenge  " + 7 + " time record: " + timeDisplayShort(player.challengeTimes[7])
    document.getElementById("challengetime8").textContent = "Challenge  " + 8 + " time record: " + timeDisplayShort(player.challengeTimes[9])
    document.getElementById("challengetime9").textContent = "Challenge  " + 9 + " time record: " + timeDisplayShort(player.challengeTimes[3])
    document.getElementById("challengetime10").textContent = "Challenge " + 10 + " time record: " + timeDisplayShort(player.challengeTimes[2])
    document.getElementById("challengetime11").textContent = "Challenge " + 11 + " time record: " + timeDisplayShort(player.challengeTimes[10])
    document.getElementById("challengetime12").textContent = "Challenge " + 12 + " time record: " + timeDisplayShort(player.challengeTimes[5])
    document.getElementById("challengetime13").textContent = "Challenge " + 13 + " time record: " + timeDisplayShort(player.challengeTimes[11])
    document.getElementById("challengetime14").textContent = "Challenge " + 14 + " time record: " + timeDisplayShort(player.challengeTimes[12])
	var temp = 0
	for (var i=0; i<13; i++) {
		temp += player.challengeTimes[i]
	}
	document.getElementById("challengetimesum").textContent = "Sum of challenge time records is " + timeDisplayShort(temp)

	temp = 0
    for (var i=0; i<10; i++) {
        document.getElementById("infchallengetime"+(i+1)).textContent = "Infinity Challenge " + (i+1) + " time record: " + timeDisplayShort(player.infchallengeTimes[i])
		temp += player.infchallengeTimes[i]
    }
    document.getElementById("infchallengetimengm3_1").textContent = "Infinity Challenge NG-3-1 time record: " + timeDisplayShort(player.infchallengeTimes[10])
    temp += player.infchallengeTimes[10]
    document.getElementById("infchallengetimengm3_2").textContent = "Infinity Challenge NG-3-2 time record: " + timeDisplayShort(player.infchallengeTimes[11])
    temp += player.infchallengeTimes[11]
    document.getElementById("infchallengetimengm3_3").textContent = "Infinity Challenge NG-3-3 time record: " + timeDisplayShort(player.infchallengeTimes[12])
    temp += player.infchallengeTimes[12]
    document.getElementById("infchallengetimengm3_4").textContent = "Infinity Challenge NG-3-4 time record: " + timeDisplayShort(player.infchallengeTimes[13])
    temp += player.infchallengeTimes[13]
    document.getElementById("infchallengetimengm4r_1").textContent = "Infinity Challenge NG-4R-1 time record: " + timeDisplayShort(player.infchallengeTimes[14])
    temp += player.infchallengeTimes[14]
    document.getElementById("infchallengetimengm4r_2").textContent = "Infinity Challenge NG-4R-2 time record: " + timeDisplayShort(player.infchallengeTimes[15])
    temp += player.infchallengeTimes[15]
    document.getElementById("infchallengetimengm4r_3").textContent = "Infinity Challenge NG-4R-3 time record: " + timeDisplayShort(player.infchallengeTimes[16])
    temp += player.infchallengeTimes[16]
    document.getElementById("infchallengetimengm4r_4").textContent = "Infinity Challenge NG-4R-4 time record: " + timeDisplayShort(player.infchallengeTimes[17])
    temp += player.infchallengeTimes[17]
    document.getElementById("infchallengetimesum").textContent = "Sum of infinity challenge time records is " + timeDisplayShort(temp)
    updateWorstChallengeTime();
}

var bestRunIppm = new Decimal(0)
function updateLastTenRuns() {
    let tempBest = 0
    var tempTime = new Decimal(0)
    var tempIP = new Decimal(0)
    for (var i=0; i<10;i++) {
        tempTime = tempTime.plus(player.lastTenRuns[i][0])
        tempIP = tempIP.plus(player.lastTenRuns[i][1])
    }
    tempTime = tempTime.dividedBy(10)
    tempIP = tempIP.dividedBy(10)
    for (var i=0; i<10; i++) {
        var ippm = player.lastTenRuns[i][1].dividedBy(player.lastTenRuns[i][0]/600)
        if (ippm.gt(tempBest)) tempBest = ippm
        var tempstring = shorten(ippm) + " IP/min"
        if (ippm<1) tempstring = shorten(ippm*60) + " IP/hour"
        document.getElementById("run"+(i+1)).textContent = "The infinity "+(i+1)+" infinities ago took " + timeDisplayShort(player.lastTenRuns[i][0]) + " and gave " + shortenDimensions(player.lastTenRuns[i][1]) +" IP. "+ tempstring
    }

    var ippm = tempIP.dividedBy(tempTime/600)
    var tempstring = shorten(ippm) + " IP/min"
    if (ippm<1) tempstring = shorten(ippm*60) + " IP/hour"
    document.getElementById("averagerun").textContent = "Last 10 infinities average time: "+ timeDisplayShort(tempTime)+" Average IP gain: "+shortenDimensions(tempIP)+" IP. "+tempstring

    if (tempBest.gte(1e8)) giveAchievement("Oh hey, you're still here");
    if (tempBest.gte(1e300)) giveAchievement("MAXIMUM OVERDRIVE");

    bestRunIppm = tempBest
}

var averageEp = new Decimal(0)
function updateLastTenEternities() {
    let tempBest = 0
    var tempTime = new Decimal(0)
    var tempEP = new Decimal(0)
    for (var i=0; i<10;i++) {
        tempTime = tempTime.plus(player.lastTenEternities[i][0])
        tempEP = tempEP.plus(player.lastTenEternities[i][1])
    }
    tempTime = tempTime.dividedBy(10)
    tempEP = tempEP.dividedBy(10)
    for (var i=0; i<10; i++) {
        var eppm = player.lastTenEternities[i][1].dividedBy(player.lastTenEternities[i][0]/600)
        if (eppm.gt(tempBest)) tempBest = eppm
        var tempstring = shorten(eppm) + " EP/min"
        if (eppm<1) tempstring = shorten(eppm*60) + " EP/hour"
        document.getElementById("eternityrun"+(i+1)).textContent = "The Eternity "+(i+1)+" eternities ago took " + timeDisplayShort(player.lastTenEternities[i][0]) + " and gave " + shortenDimensions(player.lastTenEternities[i][1]) +" EP. "+ tempstring
    }

    var eppm = tempEP.dividedBy(tempTime/600)
    var tempstring = shorten(eppm) + " EP/min"
    averageEp = tempEP
    if (eppm<1) tempstring = shorten(eppm*60) + " EP/hour"
    document.getElementById("averageEternityRun").textContent = "Last 10 eternities average time: "+ timeDisplayShort(tempTime)+" Average EP gain: "+shortenDimensions(tempEP)+" EP. "+tempstring
}

function addEternityTime(time, ep) {
    for (var i=player.lastTenEternities.length-1; i>0; i--) {
        player.lastTenEternities[i] = player.lastTenEternities[i-1]
    }
    player.lastTenEternities[0] = [time, ep]
}


document.getElementById("postInfinityButton").onclick = function() {document.getElementById("bigcrunch").click()}

function addTime(time, ip) {
    for (var i=player.lastTenRuns.length-1; i>0; i--) {
        player.lastTenRuns[i] = player.lastTenRuns[i-1]
    }
    player.lastTenRuns[0] = [time, ip]
}

var infchallengeTimes = 999999999

function checkForEndMe() {
    var temp = 0
    for (var i=0; i<13; i++) {
        temp += player.challengeTimes[i]
    }
    if (temp <= 1800) giveAchievement("Not-so-challenging")
    if (temp <= 50) giveAchievement("End me")
    var temp2 = 0
    for (var i=0; i<18;i++) {
        temp2 += player.infchallengeTimes[i]
    }
    infchallengeTimes = temp2
    if (temp2 <= 66.6) giveAchievement("Yes. This is hell.")
}


document.getElementById("bigcrunch").onclick = function () {
    var challNumber = parseInt(player.currentChallenge.replace(/[a-z]/g, ''))
    if(player.currentChallenge=="postcngm3_1")challNumber = 11
    if(player.currentChallenge=="postcngm3_2")challNumber = 12
    if(player.currentChallenge=="postcngm3_3")challNumber = 13
    if(player.currentChallenge=="postcngm3_4")challNumber = 14
    if(player.currentChallenge=="postcngm4r_1")challNumber = 15
    if(player.currentChallenge=="postcngm4r_2")challNumber = 16
    if(player.currentChallenge=="postcngm4r_3")challNumber = 17
    if(player.currentChallenge=="postcngm4r_4")challNumber = 18
    if(player.currentChallenge=="postcngm4r_5")challNumber = 19
    if(player.currentChallenge=="postcngm4r_6")challNumber = 20
    if ((player.money.gte(Number.MAX_VALUE) && !player.currentChallenge.includes("post")) || (player.currentChallenge !== "" && player.money.gte(player.challengeTarget))) {
        if ((player.bestInfinityTime > 600 && !player.break) && player.eternities === 0 && implosionCheck === 0 && player.options.animations.bigCrunch) {
            implosionCheck = 1;
            document.getElementById("body").style.animation = "implode 2s 1";
            setTimeout(function(){ document.getElementById("body").style.animation = ""; }, 2000)
            setTimeout(function(){ document.getElementById("bigcrunch").onclick(); }, 1000)
            return
        }
        implosionCheck = 0;
        giveAchievement("To infinity!");
        if (player.thisInfinityTime <= 72000) giveAchievement("That's fast!");
        if (player.thisInfinityTime <= 6000) giveAchievement("That's faster!")
        if (player.thisInfinityTime <= 600) giveAchievement("Forever isn't that long")
        if (player.thisInfinityTime <= 2) giveAchievement("Blink of an eye")
        if (player.eightAmount == 0) giveAchievement("You didn't need it anyway");
        if (player.galaxies == 1) giveAchievement("Claustrophobic");
        if (player.galaxies == 0 && player.resets == 0) giveAchievement("Zero Deaths")
        if (player.currentChallenge == "challenge2" && player.thisInfinityTime <= 1800) giveAchievement("Many Deaths")
        if (player.currentChallenge == "challenge11" && player.thisInfinityTime <= 1800) giveAchievement("Gift from the Gods")
        if (player.currentChallenge == "challenge5" && player.thisInfinityTime <= 1800) giveAchievement("Is this hell?")
        if (player.currentChallenge == "challenge3" && player.thisInfinityTime <= 100) giveAchievement("You did this again just for the achievement right?");
        if (player.firstAmount == 1 && player.resets == 0 && player.galaxies == 0 && player.currentChallenge == "challenge12") giveAchievement("ERROR 909: Dimension not found")
        if (player.currentChallenge != "" && !player.currentChallenge.includes("post") && player.challengeTimes[challNumber-2] > player.thisInfinityTime) player.challengeTimes[challNumber-2] = player.thisInfinityTime
        if (player.currentChallenge.includes("post") && player.infchallengeTimes[challNumber-1] > player.thisInfinityTime) player.infchallengeTimes[challNumber-1] = player.thisInfinityTime
        if (player.currentChallenge == "postc7" && player.thisInfinityTime <= 100) giveAchievement("Hevipelle did nothing wrong")
        if ((player.bestInfinityTime > 600 && !player.break) || (player.currentChallenge != "" && !player.options.retryChallenge)) showTab("dimensions")
        if (player.currentChallenge != "" && !player.challenges.includes(player.currentChallenge)) {
            player.challenges.push(player.currentChallenge);
            if (player.currentChallenge.indexOf('post') !== -1) {
              giveAchievement("Infinitely Challenging");
            }
        }
        if (player.challenges.length == 24) giveAchievement("Anti-antichallenged");
        if (!player.break || player.currentChallenge != "") {
            var add = gainedInfinityPoints()
            player.infinityPoints = player.infinityPoints.plus(add);
            addTime(player.thisInfinityTime, add)
        }
        else {
            player.infinityPoints = player.infinityPoints.plus(gainedInfinityPoints())
            addTime(player.thisInfinityTime, gainedInfinityPoints())
            if (gainedInfinityPoints().gte(1e150)) giveAchievement("All your IP are belong to us")
            if (gainedInfinityPoints().gte(1e200) && player.thisInfinityTime <= 20) giveAchievement("Ludicrous Speed")
            if (gainedInfinityPoints().gte(1e250) && player.thisInfinityTime <= 200) giveAchievement("I brake for nobody")
        }
        if (!player.achievements.includes("r111") && player.lastTenRuns[9][1] != 1) {
            var n = 0;
            for (i=0; i<9; i++) {
                if (player.lastTenRuns[i][1].gte(player.lastTenRuns[i+1][1].times(Number.MAX_VALUE))) n++;
            }
            if (n == 9) giveAchievement("Yo dawg, I heard you liked infinities...")
        }
        let infGain = 1;
        if (player.thisInfinityTime > 50 && player.achievements.includes("r87")) infGain = 250;
        if (player.timestudy.studies.includes(32)) infGain *= Math.max(player.resets,1);
        if (player.currentEternityChall == "eterc4") {
            infGain = 1
            if (player.infinitied >= 16 - (ECTimesCompleted("eterc4")*4)) {
                document.getElementById("challfail").style.display = "block"
                setTimeout(exitChallenge, 500)
                giveAchievement("You're a mistake")
                failureCount++
                if (failureCount > 9) giveAchievement("You're a failure")
            }
        }
        if (autoS && auto) {
          if (gainedInfinityPoints().dividedBy(player.thisInfinityTime).gt(player.autoIP) && !player.break) player.autoIP = gainedInfinityPoints().dividedBy(player.thisInfinityTime);
          if (player.thisInfinityTime<player.autoTime) player.autoTime = player.thisInfinityTime;
        }
        auto = autoS; //only allow autoing if prev crunch was autoed
        autoS = true;
        player = {
            money: new Decimal(10),
            tickSpeedCost: new Decimal(1000),
            tickspeed: new Decimal(10000),
            firstCost: new Decimal(10),
            secondCost: new Decimal(100),
            thirdCost: new Decimal(10000),
            fourthCost: new Decimal(1000000),
            fifthCost: new Decimal(1e9),
            sixthCost: new Decimal(1e13),
            seventhCost: new Decimal(1e18),
            eightCost: new Decimal(1e24),
            firstAmount: new Decimal(0),
            secondAmount: new Decimal(0),
            thirdAmount: new Decimal(0),
            fourthAmount: new Decimal(0),
            firstBought: 0,
            secondBought: 0,
            thirdBought: 0,
            fourthBought: 0,
            firstTotalBought: 0,
            secondTotalBought: 0,
            thirdTotalBought: 0,
            fourthTotalBought: 0,
            fifthAmount: new Decimal(0),
            sixthAmount: new Decimal(0),
            seventhAmount: new Decimal(0),
            eightAmount: new Decimal(0),
            fifthBought: 0,
            sixthBought: 0,
            seventhBought: 0,
            eightBought: 0,
            fifthTotalBought: 0,
            sixthTotalBought: 0,
            seventhTotalBought: 0,
            eightTotalBought: 0,
            firstPow: new Decimal(1),
            secondPow: new Decimal(1),
            thirdPow: new Decimal(1),
            fourthPow: new Decimal(1),
            fifthPow: new Decimal(1),
            sixthPow: new Decimal(1),
            seventhPow: new Decimal(1),
            eightPow: new Decimal(1),
            sacrificed: new Decimal(0),
            achievements: player.achievements,
            challenges: player.challenges,
            currentChallenge: player.currentChallenge,
            infinityUpgrades: player.infinityUpgrades,
            infinityPoints: player.infinityPoints,
            infinitied: player.infinitied + infGain,
            infinitiedBank: player.infinitiedBank,
            totalTimePlayed: player.totalTimePlayed,
            bestInfinityTime: Math.min(player.bestInfinityTime, player.thisInfinityTime),
            thisInfinityTime: 0,
            resets: 0,
            galaxies: 0,
            tickDecrease: 0.9,
            totalmoney: player.totalmoney,
            interval: null,
            lastUpdate: player.lastUpdate,
            achPow: player.achPow,
            autobuyers: player.autobuyers,
            costMultipliers: [new Decimal(1e3), new Decimal(1e4), new Decimal(1e5), new Decimal(1e6), new Decimal(1e8), new Decimal(1e10), new Decimal(1e12), new Decimal(1e15)],
            tickspeedMultiplier: new Decimal(10),
            chall2Pow: 1,
            chall3Pow: new Decimal(0.01),
            newsArray: player.newsArray,
            matter: new Decimal(0),
            chall11Pow: new Decimal(1),
            partInfinityPoint: player.partInfinityPoint,
            partInfinitied: player.partInfinitied,
            break: player.break,
            challengeTimes: player.challengeTimes,
            infchallengeTimes: player.infchallengeTimes,
            lastTenRuns: player.lastTenRuns,
            lastTenEternities: player.lastTenEternities,
            infMult: player.infMult,
            infMultCost: player.infMultCost,
            tickSpeedMultDecrease: player.tickSpeedMultDecrease,
            tickSpeedMultDecreaseCost: player.tickSpeedMultDecreaseCost,
            dimensionMultDecrease: player.dimensionMultDecrease,
            dimensionMultDecreaseCost: player.dimensionMultDecreaseCost,
            version: player.version,
            postChallUnlocked: player.postChallUnlocked,
            postC6Tier: 1,
            postC3Reward: new Decimal(1),
            overXGalaxies: player.overXGalaxies,
            spreadingCancer: player.spreadingCancer,
            infDimensionsUnlocked: player.infDimensionsUnlocked,
            infinityPower: player.infinityPower,
            infinityDimension1: player.infinityDimension1,
            infinityDimension2: player.infinityDimension2,
            infinityDimension3: player.infinityDimension3,
            infinityDimension4: player.infinityDimension4,
            infinityDimension5: player.infinityDimension5,
            infinityDimension6: player.infinityDimension6,
            infinityDimension7: player.infinityDimension7,
            infinityDimension8: player.infinityDimension8,
            infDimBuyers: player.infDimBuyers,
        timeShards: new Decimal(0),
        tickThreshold: new Decimal(1),
            timeDimension1: player.timeDimension1,
            timeDimension2: player.timeDimension2,
            timeDimension3: player.timeDimension3,
            timeDimension4: player.timeDimension4,
            timeDimension5: player.timeDimension5,
            timeDimension6: player.timeDimension6,
            timeDimension7: player.timeDimension7,
            timeDimension8: player.timeDimension8,
            eternityPoints: player.eternityPoints,
            eternities: player.eternities,
            thisEternity: player.thisEternity,
            bestEternity: player.bestEternity,
            eternityUpgrades: player.eternityUpgrades,
            epmult: player.epmult,
            epmultCost: player.epmultCost,
            totalTickGained: 0,
            offlineProd: player.offlineProd,
            offlineProdCost: player.offlineProdCost,
            extraDimPowerIncrease: player.extraDimPowerIncrease,
            dimPowerIncreaseCost: player.dimPowerIncreaseCost,
            challengeTarget: player.challengeTarget,
            replicanti: player.replicanti,
            timestudy: player.timestudy,
            eternityChalls: player.eternityChalls,
            eternityChallGoal: player.eternityChallGoal,
            currentEternityChall: player.currentEternityChall,
            eternityChallUnlocked: player.eternityChallUnlocked,
            etercreq: player.etercreq,
            autoIP: player.autoIP,
            autoTime: player.autoTime,
            infMultBuyer: player.infMultBuyer,
            autoCrunchMode: player.autoCrunchMode,
            respec: player.respec,
            eternityBuyer: player.eternityBuyer,
            eterc8ids: player.eterc8ids,
            eterc8repl: player.eterc8repl,
            tickBoughtThisInf: {
              current: 0,
              pastResets: [{'resets': 0, 'bought': 0}]
            },
            dimlife: player.dimlife,
            dead: player.dead,
            dilation: player.dilation,
            why: player.why,
	          galacticSacrifice: newGalacticDataOnInfinity(),
            options: player.options,
			
			
	// for aarex modifications
	aarexModifications: {
		ngmX: 4,
		ngmm: 3,
		ngm4r: 1,
		newGame4MinusRespeccedVersion: newGame4MinusRespeccedVersion

	},
	
	tickspeedBoosts: 0,
	tdBoosts: 0,

    timeless: player.timeless,
        };

	resetTimeDimensions(1);
        if (player.challenges.length >= 2) giveAchievement("Daredevil");
        if (player.challenges.length == 14) giveAchievement("AntiChallenged");
        if (player.challenges.length == 24) giveAchievement("Anti-antichallenged");

        if (player.bestInfinityTime <= 0.01) giveAchievement("Less than or equal to 0.001");

        if (!player.options.retryChallenge) player.currentChallenge = ""

        if (player.resets == 0 && player.currentChallenge == "") {
            if (player.infinityUpgrades.includes("skipReset1")) player.resets++;
            if (player.infinityUpgrades.includes("skipReset2")) player.resets++;
            if (player.infinityUpgrades.includes("skipReset3")) player.resets++;
            if (player.infinityUpgrades.includes("skipResetGalaxy")) {
                player.resets++;
                if (player.galaxies == 0) player.galaxies = 1
            }
		if (player.resets > 0)player.tickspeedBoosts = player.tdBoosts = Math.pow(2,player.resets);
        }

        if (player.replicanti.unl && !player.achievements.includes("r95")) player.replicanti.amount = new Decimal(1)

        player.replicanti.galaxies = (player.timestudy.studies.includes(33)) ? Math.floor(player.replicanti.galaxies/2) :0

        decreaseDimCosts();
        setInitialDimensionPower();


        if (player.currentChallenge == "challenge12" || player.currentChallenge == "postc4" || player.currentChallenge == "postc8") document.getElementById("matter").style.display = "block";
        else document.getElementById("matter").style.display = "none";

        if (player.currentChallenge == "challenge13" || player.currentChallenge == "postc4" || player.currentChallenge === "postcngm3_3" || player.challenges.includes("postcngm3_3")) document.getElementById("chall13Mult").style.display = "block";
        else document.getElementById("chall13Mult").style.display = "none";

        document.getElementById("replicantireset").innerHTML = "Reset replicanti amount, but get a free galaxy<br>"+player.replicanti.galaxies + " replicated galaxies created."

        if (player.achievements.includes("r36")) player.tickspeed = player.tickspeed.times(0.98);
        if (player.achievements.includes("r45")) player.tickspeed = player.tickspeed.times(0.98);
        if (player.achievements.includes("r66")) player.tickspeed = player.tickspeed.times(0.98);
        if (player.achievements.includes("r83")) player.tickspeed = player.tickspeed.times(Decimal.pow(0.95,player.galaxies));
        if (player.eternities < 30) {
            document.getElementById("secondRow").style.display = "none";
            document.getElementById("thirdRow").style.display = "none";
            document.getElementById("tickSpeed").style.visibility = "hidden";
            document.getElementById("tickSpeedMax").style.visibility = "hidden";
            document.getElementById("tickLabel").style.visibility = "hidden";
            document.getElementById("tickSpeedAmount").style.visibility = "hidden";
            document.getElementById("tickSpeedPurchases").style.visibility = "hidden";
            document.getElementById("fourthRow").style.display = "none";
            document.getElementById("fifthRow").style.display = "none";
            document.getElementById("sixthRow").style.display = "none";
            document.getElementById("seventhRow").style.display = "none";
            document.getElementById("eightRow").style.display = "none";
        }
        document.getElementById("matter").style.display = "none";
        if (player.challenges.includes("postcngm3_3")) document.getElementById("chall13Mult").style.display = "block";
        else document.getElementById("chall13Mult").style.display = "none";
        document.getElementById("quickReset").style.display = "none";

        checkForEndMe()

        try {
            kongregate.stats.submit('Infinitied', getInfinitied());
            kongregate.stats.submit('Fastest Infinity time (ms)', Math.floor(player.bestInfinityTime * 100))

        } catch (err) {console.log("Couldn't load Kongregate API")}

        if (player.infinitied >= 10) giveAchievement("That's a lot of infinites");
        if (player.infinitied >= 1 && !player.challenges.includes("challenge1")) player.challenges.push("challenge1");


        updateAutobuyers();
        if (player.challenges.includes("challenge1")) player.money = new Decimal(100)
        if (player.achievements.includes("r37")) player.money = new Decimal(1000);
        if (player.achievements.includes("r54")) player.money = new Decimal(2e5);
        if (player.achievements.includes("r55")) player.money = new Decimal(1e10);
        if (player.achievements.includes("r78")) player.money = new Decimal(1e25);
        resetInfDimensions();
        player.tickspeed = player.tickspeed.times(Decimal.pow(getTickSpeedMultiplier(), player.totalTickGained))
        player.postC3Reward = player.postC3Reward.times(Decimal.pow(getPostC3RewardMult(), player.totalTickGained))
        updateTickSpeed();
        IPminpeak = new Decimal(0)


        if (player.eternities > 10 && player.currentEternityChall !== "eterc8" && player.currentEternityChall !== "eterc2" && player.currentEternityChall !== "eterc10") {
            for (var i=1;i<player.eternities-9 && i < 9; i++) {
                if (player.infDimBuyers[i-1]) {
                    buyMaxInfDims(i)
                    buyManyInfinityDimension(i)
                }
            }
        }

        if (player.eternities >= 40 && player.replicanti.auto[0] && player.currentEternityChall !== "eterc8") {
            while (player.infinityPoints.gte(player.replicanti.chanceCost) && player.currentEternityChall !== "eterc8" && (player.replicanti.chance < 1 || player.achievements.includes("ngm4r4"))) upgradeReplicantiChance()
        }

        if (player.eternities >= 60 && player.replicanti.auto[1] && player.currentEternityChall !== "eterc8") {
            while (player.infinityPoints.gte(player.replicanti.intervalCost) && player.currentEternityChall !== "eterc8" && ((player.timestudy.studies.includes(22)) ? player.replicanti.interval > 1 : player.replicanti.interval > 50)) upgradeReplicantiInterval()
        }

        if (player.eternities >= 80 && player.replicanti.auto[2] && player.currentEternityChall !== "eterc8") {
            while (player.infinityPoints.gte(player.replicanti.galCost)) upgradeReplicantiGalaxy()
        }

        Marathon2 = 0;

    }
  updateChallenges();
  updateChallengeTimes()
  updateLastTenRuns()


}



function getKeptChallenges () {
  return (player.eternities > 0 && player.achievements.includes("r133")) ?
  ["challenge1", "challenge2", "challenge3",
  "challenge4", "challenge5", "challenge6",
  "challenge7", "challenge8", "challenge9",
  "challenge10", "challenge11", "challenge12",
  "challenge13", "challenge14",
  "postc1", "postc2", "postc3", "postc4",
  "postc5", "postc6", "postc7", "postc8",
  "postc9", "postc10",

  // additional challenges

  "postcngm3_1","postcngm3_2","postcngm3_3","postcngm3_4","postcngm4r_1","postcngm4r_2","postcngm4r_3","postcngm4r_4",
] :
  (player.eternities > 6) ?
  ["challenge1", "challenge2", "challenge3",
  "challenge4", "challenge5", "challenge6",
  "challenge7", "challenge8", "challenge9",
  "challenge10", "challenge11", "challenge12",
  "challenge13", "challenge14",

  // additional challenges

  "postcngm3_1","postcngm3_2","postcngm3_3","postcngm3_4","postcngm4r_1","postcngm4r_2","postcngm4r_3","postcngm4r_4",
] :
  (player.eternities > 0) ?
  ["challenge1", "challenge2", "challenge3",
  "challenge4", "challenge5", "challenge6",
  "challenge7", "challenge8", "challenge9",
  "challenge10", "challenge11", "challenge12",
  "challenge13", "challenge14"] : [];
}


function respecToggle() {
    if (player.respec) {
        player.respec = false
        document.getElementById("respec").className = "storebtn"
    } else {
        player.respec = true
        document.getElementById("respec").className = "timestudybought"
    }
}

function gainedTimelessShards() {
	let power=3;
	if(player.achievements.includes("r115"))power=power+0.2*totalEc()
    let ret=Decimal.pow(Decimal.log10(player.timeShards)/750,power).times(Decimal.pow(2, player.timeless.rebuyables[2]||0));
	if(player.achievements.includes("r117"))ret=ret.times(Decimal.pow(player.eightTotalBought,0.1));
	if(player.achievements.includes("r122"))ret=ret.times(Decimal.pow(player.firstTotalBought,0.2));
	if(player.galacticSacrifice.upgrades.includes(75))ret=ret.mul(galUpgrade75());
	if(player.achievements.includes("r131"))ret=ret.times(Math.pow(player.infinitiedBank+1,0.05));
	if(player.timeless.upgrades.includes(32) && ret.gte(0)){
		player.timeless.shards=player.timeless.shards.max(ret);
	}
	return ret.sub(player.timeless.shards).floor().max(0);
}

function nextTimelessShardAt() {
	let power=3;
	if(player.achievements.includes("r115"))power=power+0.2*totalEc()
	let ret=player.timeless.shards.add(1).add(gainedTimelessShards());
	if(player.achievements.includes("r117"))ret=ret.div(Decimal.pow(player.eightTotalBought,0.1));
	if(player.achievements.includes("r122"))ret=ret.div(Decimal.pow(player.firstTotalBought,0.2));
	if(player.galacticSacrifice.upgrades.includes(75))ret=ret.div(galUpgrade75());
	if(player.achievements.includes("r131"))ret=ret.div(Math.pow(player.infinitiedBank+1,0.05));
    return Decimal.pow("1e750",ret.times(Decimal.pow(0.5, player.timeless.rebuyables[2]||0)).pow(1/power));
}

function eternity(force, auto) {
    if ((player.infinityPoints.gte(Number.MAX_VALUE) && (!player.options.eternityconfirm || auto || player.timeless.active || force || confirm("Eternity will reset everything except achievements and challenge records. You will also gain an Eternity point and unlock various upgrades."))) || force === true) {
        if (player.timeless.active)force = true;
        if (force) player.currentEternityChall = "";
        if (player.currentEternityChall !== "" && player.infinityPoints.lt(player.eternityChallGoal)) return false
        if (player.thisEternity<player.bestEternity && !force) {
            player.bestEternity = player.thisEternity
        }
        if (player.bestEternity < 600) giveAchievement("That wasn't an eternity");
         if (player.bestEternity <= 0.01) giveAchievement("Less than or equal to 0.001");
        if (player.thisEternity < 2 && !force) giveAchievement("Eternities are the new infinity")
        if (player.currentEternityChall == "eterc6" && ECTimesCompleted("eterc6") < 5) player.dimensionMultDecrease = (3 - 0.2 * (ECTimesCompleted("eterc6")+1))
        if (player.currentEternityChall == "eterc11" && ECTimesCompleted("eterc11") < 5) player.tickSpeedMultDecrease = (2 - 0.07 * (ECTimesCompleted("eterc11")+1))
        if (player.infinitied < 10 && !force) giveAchievement("Do you really need a guide for this?");
        if (Decimal.round(player.replicanti.amount) == 9 && !force) giveAchievement("We could afford 9");
        if (player.dimlife && !force) giveAchievement("8 nobody got time for that")
        if (player.dead && !force) giveAchievement("You're already dead.")
        if (player.infinitied <= 1 && !force) giveAchievement("Do I really need to infinity")
        if (gainedEternityPoints().gte("1e600") && player.thisEternity <= 600 && player.dilation.active && !force) giveAchievement("Now you're thinking with dilation!")
        temp = []
        if (!force)player.eternityPoints = player.eternityPoints.plus(gainedEternityPoints())
        if (!force && gainedEternityPoints().gte(1e87))giveAchievement("Faster than a cubed eternal potato")
        if (!force)addEternityTime(player.thisEternity, gainedEternityPoints())
        else addEternityTime(player.thisEternity, new Decimal(0))
        if (player.currentEternityChall !== "") {
            player.lastTenEternities[0][2]=player.eternityChallUnlocked
            if (player.eternityChalls[player.currentEternityChall] === undefined) {
                player.eternityChalls[player.currentEternityChall] = 1
            } else if (player.eternityChalls[player.currentEternityChall] < 5) player.eternityChalls[player.currentEternityChall] += 1
            player.etercreq = 0
            respecTimeStudies()
            if (Object.keys(player.eternityChalls).length >= 10) {
                var eterchallscompletedtotal = 0;
                for (i=1; i<Object.keys(player.eternityChalls).length+1; i++) {
                    eterchallscompletedtotal += player.eternityChalls["eterc"+i]
                }
                if (eterchallscompletedtotal >= 50) {
                    giveAchievement("5 more eternities until the update");
                }
            }
        }
        for (var i=0; i<player.challenges.length; i++) {
            if (!player.challenges[i].includes("post") && player.eternities > 1) temp.push(player.challenges[i])
        }
        if (player.achievements.includes("r131")) player.infinitiedBank += Math.floor(player.infinitied*0.05)
        if (player.infinitiedBank > 5000000000) giveAchievement("No ethical consumption");
        if (player.dilation.active && (!force || player.infinityPoints.gte(Number.MAX_VALUE))) {
            let tachyonGain = Math.max(Math.pow(Decimal.log10(player.money) / 400, 1.5) * (Math.pow(3, player.dilation.rebuyables[3])) - player.dilation.totalTachyonParticles, 0)
            player.dilation.totalTachyonParticles = player.dilation.totalTachyonParticles.plus(tachyonGain)
            player.dilation.tachyonParticles = player.dilation.tachyonParticles.plus(tachyonGain)
            player.lastTenEternities[0][1]=tachyonGain
            player.lastTenEternities[0][2]="d2"
        }
        if (player.timeless.active) {
            let timelessGain = gainedTimelessShards();
            player.timeless.shards = player.timeless.shards.plus(timelessGain)
            player.lastTenEternities[0][1]=timelessGain
            player.lastTenEternities[0][2]="timeless"
        }
        player.challenges = temp
        player = {
            money: new Decimal(10),
            tickSpeedCost: new Decimal(1000),
            tickspeed: new Decimal(10000),
            firstCost: new Decimal(10),
            secondCost: new Decimal(100),
            thirdCost: new Decimal(10000),
            fourthCost: new Decimal(1000000),
            fifthCost: new Decimal(1e9),
            sixthCost: new Decimal(1e13),
            seventhCost: new Decimal(1e18),
            eightCost: new Decimal(1e24),
            firstAmount: new Decimal(0),
            secondAmount: new Decimal(0),
            thirdAmount: new Decimal(0),
            fourthAmount: new Decimal(0),
            firstBought: 0,
            secondBought: 0,
            thirdBought: 0,
            fourthBought: 0,
            firstTotalBought: 0,
            secondTotalBought: 0,
            thirdTotalBought: 0,
            fourthTotalBought: 0,
            fifthAmount: new Decimal(0),
            sixthAmount: new Decimal(0),
            seventhAmount: new Decimal(0),
            eightAmount: new Decimal(0),
            fifthBought: 0,
            sixthBought: 0,
            seventhBought: 0,
            eightBought: 0,
            fifthTotalBought: 0,
            sixthTotalBought: 0,
            seventhTotalBought: 0,
            eightTotalBought: 0,
            firstPow: new Decimal(1),
            secondPow: new Decimal(1),
            thirdPow: new Decimal(1),
            fourthPow: new Decimal(1),
            fifthPow: new Decimal(1),
            sixthPow: new Decimal(1),
            seventhPow: new Decimal(1),
            eightPow: new Decimal(1),
            sacrificed: new Decimal(0),
            achievements: player.achievements,
            challenges: getKeptChallenges(),
            currentChallenge: "",
            infinityUpgrades: player.infinityUpgrades,
            infinityPoints: new Decimal(0),
            infinitied: 0,
            infinitiedBank: player.infinitiedBank,
            totalTimePlayed: player.totalTimePlayed,
            bestInfinityTime: 9999999999,
            thisInfinityTime: 0,
            resets: (player.eternities > 2) ? 4 : 0,
            galaxies: (player.eternities > 2) ? 1 : 0,
            tickDecrease: 0.9,
            totalmoney: player.totalmoney,
            interval: null,
            lastUpdate: player.lastUpdate,
            achPow: player.achPow,
            autobuyers: (player.eternities > 0) ? player.autobuyers : [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
            partInfinityPoint: 0,
            partInfinitied: 0,
            break: player.eternities > 0 ? player.break : false,
            costMultipliers: [new Decimal(1e3), new Decimal(1e4), new Decimal(1e5), new Decimal(1e6), new Decimal(1e8), new Decimal(1e10), new Decimal(1e12), new Decimal(1e15)],
            tickspeedMultiplier: new Decimal(10),
            chall2Pow: 1,
            chall3Pow: new Decimal(0.01),
            newsArray: player.newsArray,
            matter: new Decimal(0),
            chall11Pow: new Decimal(1),
            challengeTimes: player.challengeTimes,
            infchallengeTimes: player.infchallengeTimes,
            lastTenRuns: [[600*60*24*31, new Decimal(1)], [600*60*24*31, new Decimal(1)], [600*60*24*31, new Decimal(1)], [600*60*24*31, new Decimal(1)], [600*60*24*31, new Decimal(1)], [600*60*24*31, new Decimal(1)], [600*60*24*31, new Decimal(1)], [600*60*24*31, new Decimal(1)], [600*60*24*31, new Decimal(1)], [600*60*24*31, new Decimal(1)]],
            lastTenEternities: player.lastTenEternities,
            infMult: new Decimal(1),
            infMultCost: new Decimal(10),
            tickSpeedMultDecrease: player.eternities > 18 ? player.tickSpeedMultDecrease : 10,
            tickSpeedMultDecreaseCost: player.eternities > 18 ? player.tickSpeedMultDecreaseCost : 3e6,
            dimensionMultDecrease: player.eternities > 18 ? player.dimensionMultDecrease : 10,
            dimensionMultDecreaseCost: player.eternities > 18 ? player.dimensionMultDecreaseCost : 1e8,
            version: player.version,
            postChallUnlocked: (player.achievements.includes("r133")) ? 8 : 0,
            postC6Tier: 1,
            postC3Reward: new Decimal(1),
            overXGalaxies: player.overXGalaxies,
            spreadingCancer: player.spreadingCancer,
            infDimensionsUnlocked: [false, false, false, false, false, false, false, false],
            infinityPower: new Decimal(1),
            infinityDimension1 : {
                cost: new Decimal(1e8),
                amount: new Decimal(0),
                bought: 0,
                power: new Decimal(1),
                baseAmount: 0
            },
            infinityDimension2 : {
                cost: new Decimal(1e9),
                amount: new Decimal(0),
                bought: 0,
                power: new Decimal(1),
                baseAmount: 0
            },
            infinityDimension3 : {
                cost: new Decimal(1e10),
                amount: new Decimal(0),
                bought: 0,
                power: new Decimal(1),
                baseAmount: 0
            },
            infinityDimension4 : {
                cost: new Decimal(1e20),
                amount: new Decimal(0),
                bought: 0,
                power: new Decimal(1),
                baseAmount: 0
            },
            infinityDimension5 : {
                cost: new Decimal(1e140),
                amount: new Decimal(0),
                bought: 0,
                power: new Decimal(1),
                baseAmount: 0
            },
            infinityDimension6 : {
                cost: new Decimal(1e200),
                amount: new Decimal(0),
                bought: 0,
                power: new Decimal(1),
                baseAmount: 0
            },
            infinityDimension7 : {
                cost: new Decimal(1e250),
                amount: new Decimal(0),
                bought: 0,
                power: new Decimal(1),
                baseAmount: 0
            },
            infinityDimension8 : {
                cost: new Decimal(1e280),
                amount: new Decimal(0),
                bought: 0,
                power: new Decimal(1),
                baseAmount: 0
            },
            infDimBuyers: player.infDimBuyers,
            timeShards: new Decimal(0),
            tickThreshold: new Decimal(1),
            totalTickGained: 0,
            timeDimension1: player.timeDimension1,
            timeDimension2: player.timeDimension2,
            timeDimension3: player.timeDimension3,
            timeDimension4: player.timeDimension4,
            timeDimension5: player.timeDimension5,
            timeDimension6: player.timeDimension6,
            timeDimension7: player.timeDimension7,
            timeDimension8: player.timeDimension8,
            eternityPoints: player.eternityPoints,
            eternities: player.eternities+(force?0:1),
            thisEternity: 0,
            bestEternity: player.bestEternity,
            eternityUpgrades: player.eternityUpgrades,
            epmult: player.epmult,
            epmultCost: player.epmultCost,
            totalTickGained: 0,
            offlineProd: player.eternities > 18 ? player.offlineProd : 0,
            offlineProdCost: player.eternities > 18 ? player.offlineProdCost : 1e7,
            extraDimPowerIncrease: player.eternities > 18 ? player.extraDimPowerIncrease : 0,
            dimPowerIncreaseCost: player.eternities > 18 ? player.dimPowerIncreaseCost : new Decimal(1e3),
            challengeTarget: 0,
            replicanti: {
                amount: player.eternities > 48 ? new Decimal(1) : new Decimal(0),
                unl: player.eternities > 48 ? true : false,
                chance: 0.01,
                chanceCost: new Decimal(1e90),
                interval: 1000,
                intervalCost: new Decimal(1e80),
                gal: 0,
                galaxies: 0,
                galCost: new Decimal(1e110),
                galaxybuyer: (player.eternities > 1) ? player.replicanti.galaxybuyer : undefined,
                auto: player.replicanti.auto
            },
            timestudy: player.timestudy,
            eternityChalls: player.eternityChalls,
            eternityChallGoal: new Decimal(Number.MAX_VALUE),
            currentEternityChall: "",
            eternityChallUnlocked: player.eternityChallUnlocked,
            etercreq: player.etercreq,
            autoIP: new Decimal(0),
            autoTime: 1e300,
            infMultBuyer: player.infMultBuyer,
            autoCrunchMode: player.autoCrunchMode,
            respec: player.respec,
            eternityBuyer: player.eternityBuyer,
            eterc8ids: 50,
            eterc8repl: 40,
            tickBoughtThisInf: {
              current: 0,
              pastResets: [{'resets': 0, 'bought': 0}]
            },
            dimlife: true,
            dead: true,
            dilation: {
                studies: player.dilation.studies,
                active: false,
                tachyonParticles: player.dilation.tachyonParticles,
                dilatedTime: player.dilation.dilatedTime,
                totalTachyonParticles: player.dilation.totalTachyonParticles,
                nextThreshold: player.dilation.nextThreshold,
                freeGalaxies: player.dilation.freeGalaxies,
                upgrades: player.dilation.upgrades,
                rebuyables: player.dilation.rebuyables
            },
            why: player.why,
	          galacticSacrifice: player.eternities>=5?player.galacticSacrifice:{
              galaxyPoints: new Decimal(0),
              last: Date.now(),
              times: 0,
              upgrades: []
            },
            options: player.options,
			
	// for aarex modifications
	aarexModifications: {
		ngmX: 4,
		ngmm: 3,
		ngm4r: 1,
		newGame4MinusRespeccedVersion: newGame4MinusRespeccedVersion

	},
	
	tickspeedBoosts: 0,
	tdBoosts: 0,
	
    timeless: player.timeless,
        };
		player.timeless.active=false;
        if (player.respec) respecTimeStudies()
        player.respec = false
        giveAchievement("Time is relative")
        if (player.eternities >= 100) giveAchievement("This mile took an Eternity");
        if (player.replicanti.unl) player.replicanti.amount = new Decimal(1)
        player.replicanti.galaxies = 0
        document.getElementById("respec").className = "storebtn"
        if (player.achievements.includes("r36")) player.tickspeed = player.tickspeed.times(0.98);
        if (player.achievements.includes("r45")) player.tickspeed = player.tickspeed.times(0.98);

        if (player.eternities <= 30) {
            document.getElementById("secondRow").style.display = "none";
            document.getElementById("thirdRow").style.display = "none";
            document.getElementById("tickSpeed").style.visibility = "hidden";
            document.getElementById("tickSpeedMax").style.visibility = "hidden";
            document.getElementById("tickLabel").style.visibility = "hidden";
            document.getElementById("tickSpeedAmount").style.visibility = "hidden";
            document.getElementById("tickSpeedPurchases").style.visibility = "hidden";
            document.getElementById("fourthRow").style.display = "none";
            document.getElementById("fifthRow").style.display = "none";
            document.getElementById("sixthRow").style.display = "none";
            document.getElementById("seventhRow").style.display = "none";
            document.getElementById("eightRow").style.display = "none";
        }
        document.getElementById("matter").style.display = "none";
        if (player.challenges.includes("postcngm3_3")) document.getElementById("chall13Mult").style.display = "block";
        else document.getElementById("chall13Mult").style.display = "none";
        document.getElementById("quickReset").style.display = "none";
        if (player.infinitied >= 1 && !player.challenges.includes("challenge1")) player.challenges.push("challenge1");
        var autobuyers = document.getElementsByClassName('autoBuyerDiv')
        if (player.eternities < 2) {
            for (var i=0; i<autobuyers.length;i++) autobuyers.item(i).style.display = "none"
            document.getElementById("buyerBtnDimBoost").style.display = "inline-block"
            document.getElementById("buyerBtnGalaxies").style.display = "inline-block"
            document.getElementById("buyerBtnInf").style.display = "inline-block"
            document.getElementById("buyerBtnTickSpeed").style.display = "inline-block"
        }
        updateAutobuyers();
        if (player.achievements.includes("r37")) player.money = new Decimal(1000);
        if (player.achievements.includes("r54")) player.money = new Decimal(2e5);
        if (player.achievements.includes("r55")) player.money = new Decimal(1e10);
        if (player.achievements.includes("r78")) player.money = new Decimal(1e25);
        if (player.achievements.includes("r104")) player.infinityPoints = new Decimal(2e25);
        resetInfDimensions();
        updateChallenges();
        updateChallengeTimes()
        updateLastTenRuns()
        updateLastTenEternities()
        if (!player.achievements.includes("r133")) {
            var infchalls = Array.from(document.getElementsByClassName('infchallengediv'))
            for (var i = 0; i< infchalls.length; i++) if(!infchalls[i].id.startsWith("postcngm"))infchalls[i].style.display = "none"
        }
        IPminpeak = new Decimal(0)
        EPminpeak = new Decimal(0)
        updateMilestones()
        resetTimeDimensions()
        if (player.eternities < 20) player.autobuyers[9].bulk = 1
        if (player.eternities < 20) document.getElementById("bulkDimboost").value = player.autobuyers[9].bulk
        if (player.eternities < 50) {
            document.getElementById("replicantidiv").style.display="none"
            document.getElementById("replicantiunlock").style.display="inline-block"
        } else if (document.getElementById("replicantidiv").style.display === "none" && player.eternities >= 50) {
            document.getElementById("replicantidiv").style.display="inline-block"
            document.getElementById("replicantiunlock").style.display="none"
        }
        try {
            kongregate.stats.submit('Eternities', player.eternities);
        } catch (err) {console.log("Couldn't load Kongregate API")}
        if (player.eternities > 2 && player.replicanti.galaxybuyer === undefined) player.replicanti.galaxybuyer = false
        document.getElementById("infinityPoints1").innerHTML = "You have <span class=\"IPAmount1\">"+shortenDimensions(player.infinityPoints)+"</span> Infinity points."
        document.getElementById("infinityPoints2").innerHTML = "You have <span class=\"IPAmount2\">"+shortenDimensions(player.infinityPoints)+"</span> Infinity points."
        if (player.eternities < 2) document.getElementById("break").textContent = "BREAK INFINITY"
        document.getElementById("replicantireset").innerHTML = "Reset replicanti amount, but get a free galaxy<br>"+player.replicanti.galaxies + " replicated galaxies created."
        document.getElementById("eternitybtn").style.display = player.infinityPoints.gte(player.eternityChallGoal) ? "inline-block" : "none"
if(player.timeless.active)document.getElementById("eternitybtn").style.display = "inline-block"
        document.getElementById("eternityPoints2").style.display = "inline-block"
        document.getElementById("eternitystorebtn").style.display = "inline-block"
        document.getElementById("infiMult").innerHTML = "Multiply infinity points from all sources by " + formatValue(player.options.notation,getIPMultMultiplier(),2,2) + "<br>Currently:" +shorten(getIPMult()) +"x<br>Cost: "+shortenCosts(player.infMultCost)+" IP"
        updateEternityUpgrades()
        document.getElementById("totaltickgained").textContent = "You've gained "+player.totalTickGained.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",")+" tickspeed upgrades."
		if (player.achievements.includes("r105"))document.getElementById("totaltickgained").textContent += " 'Infinite Time' multiplier: "+shorten(player.postC3Reward.pow(infiniteTimeStrength()))+".";
        if (player.tickspeedBoosts)document.getElementById("totaltickgained").textContent += " Tickspeed Boosts are reducing timeshard requirement by "+shorten(Math.pow(player.tickspeedBoosts,0.9)*100*Math.max(Math.sqrt(player.galacticSacrifice.galaxyPoints.max(1).log10()) / 3,1))+" tickspeed upgrades";
        updateTickSpeed();
        playerInfinityUpgradesOnEternity()
        document.getElementById("eternityPoints2").innerHTML = "You have <span class=\"EPAmount2\">"+shortenDimensions(player.eternityPoints)+"</span> Eternity point"+((player.eternityPoints.eq(1)) ? "." : "s.")+(player.eternities >= 1 ?("<br>Eternity point gain is dilated after "+shorten(Decimal.pow(10,getDilationStart()))+".<br>Multiplier to EP gain pre-dilation based on eternities: "+shorten(EternitiesEPMult().div(3))):"");
        if (player.achievements.includes("r102"))document.getElementById("eternityPoints2").innerHTML += "<br>Multiplier to EP gain post-dilation based on eternities: "+shorten(player.eternities+1)
			updateEternityChallenges()
        if (player.eternities <= 1 && !force) {
            showTab("dimensions")
            showDimTab("timedimensions")
            loadAutoBuyerSettings()
        }
        Marathon2 = 0;
    }
}

function exitChallenge() {
    if (player.currentChallenge !== "") {
        document.getElementById(player.currentChallenge).textContent = "Start"
        startChallenge("");
        updateChallenges();
    } else if (player.currentEternityChall !== "") {
        player.currentEternityChall = ""
        player.eternityChallGoal = new Decimal(Number.MAX_VALUE)
        eternity(true)
        updateEternityChallenges();
    }
}

function inQuickResetChallenge () {
  return (player.currentChallenge == "challenge12" || player.currentChallenge == "challenge9" || player.currentChallenge == "challenge5" || player.currentChallenge == "challenge14" ||
      player.currentChallenge == "postc4" || player.currentChallenge == "postc6" || player.currentChallenge == "postc8" || player.currentChallenge == "postc10");
}

function startChallenge(name, target) {
  if (player.options.challConf || name == "" ? true : confirm("You will start over with just your infinity upgrades, and achievements. You need to reach a set goal with special conditions. NOTE: The rightmost infinity upgrade column doesn't work on challenges.")) {
    if (player.currentChallenge != "") document.getElementById(player.currentChallenge).textContent = "Start"
    player = {
        money: new Decimal(10),
        tickSpeedCost: new Decimal(1000),
        tickspeed: new Decimal(10000),
        firstCost: new Decimal(10),
        secondCost: new Decimal(100),
        thirdCost: new Decimal(10000),
        fourthCost: new Decimal(1000000),
        fifthCost: new Decimal(1e9),
        sixthCost: new Decimal(1e13),
        seventhCost: new Decimal(1e18),
        eightCost: new Decimal(1e24),
        firstAmount: new Decimal(0),
        secondAmount: new Decimal(0),
        thirdAmount: new Decimal(0),
        fourthAmount: new Decimal(0),
        firstBought: 0,
        secondBought: 0,
        thirdBought: 0,
        fourthBought: 0,
        firstTotalBought: 0,
        secondTotalBought: 0,
        thirdTotalBought: 0,
        fourthTotalBought: 0,
        fifthAmount: new Decimal(0),
        sixthAmount: new Decimal(0),
        seventhAmount: new Decimal(0),
        eightAmount: new Decimal(0),
        fifthBought: 0,
        sixthBought: 0,
        seventhBought: 0,
        eightBought: 0,
        fifthTotalBought: 0,
        sixthTotalBought: 0,
        seventhTotalBought: 0,
        eightTotalBought: 0,
        firstPow: new Decimal(1),
        secondPow: new Decimal(1),
        thirdPow: new Decimal(1),
        fourthPow: new Decimal(1),
        fifthPow: new Decimal(1),
        sixthPow: new Decimal(1),
        seventhPow: new Decimal(1),
        eightPow: new Decimal(1),
        sacrificed: new Decimal(0),
      achievements: player.achievements,
      challenges: player.challenges,
      currentChallenge: name,
      infinityUpgrades: player.infinityUpgrades,
      infinityPoints: player.infinityPoints,
      infinitied: player.infinitied,
      infinitiedBank: player.infinitiedBank,
      totalTimePlayed: player.totalTimePlayed,
      bestInfinityTime: player.bestInfinityTime,
      thisInfinityTime: 0,
      resets: 0,
      galaxies: 0,
      tickDecrease: 0.9,
      totalmoney: player.totalmoney,
      interval: null,
      lastUpdate: player.lastUpdate,
      achPow: player.achPow,
      autobuyers: player.autobuyers,
      costMultipliers: [new Decimal(1e3), new Decimal(1e4), new Decimal(1e5), new Decimal(1e6), new Decimal(1e8), new Decimal(1e10), new Decimal(1e12), new Decimal(1e15)],
      tickspeedMultiplier: new Decimal(10),
      chall2Pow: 1,
      chall3Pow: new Decimal(0.01),
      matter: new Decimal(0),
      newsArray: player.newsArray,
      chall11Pow: new Decimal(1),
      partInfinityPoint: player.partInfinityPoint,
      partInfinitied: player.partInfinitied,
      break: player.break,
      challengeTimes: player.challengeTimes,
      infchallengeTimes: player.infchallengeTimes,
      lastTenRuns: player.lastTenRuns,
      lastTenEternities: player.lastTenEternities,
      infMult: player.infMult,
      infMultCost: player.infMultCost,
      tickSpeedMultDecrease: player.tickSpeedMultDecrease,
      tickSpeedMultDecreaseCost: player.tickSpeedMultDecreaseCost,
      dimensionMultDecrease: player.dimensionMultDecrease,
      dimensionMultDecreaseCost: player.dimensionMultDecreaseCost,
      version: player.version,
      postChallUnlocked: player.postChallUnlocked,
      postC6Tier: 1,
      postC3Reward: new Decimal(1),
      overXGalaxies: player.overXGalaxies,
      spreadingCancer: player.spreadingCancer,
      infDimensionsUnlocked: player.infDimensionsUnlocked,
      infinityPower: player.infinityPower,
      infinityDimension1: player.infinityDimension1,
      infinityDimension2: player.infinityDimension2,
      infinityDimension3: player.infinityDimension3,
      infinityDimension4: player.infinityDimension4,
      infinityDimension5: player.infinityDimension5,
      infinityDimension6: player.infinityDimension6,
      infinityDimension7: player.infinityDimension7,
      infinityDimension8: player.infinityDimension8,
      infDimBuyers: player.infDimBuyers,
        timeShards: new Decimal(0),
        tickThreshold: new Decimal(1),
      timeDimension1: player.timeDimension1,
      timeDimension2: player.timeDimension2,
      timeDimension3: player.timeDimension3,
      timeDimension4: player.timeDimension4,
      timeDimension5: player.timeDimension5,
      timeDimension6: player.timeDimension6,
      timeDimension7: player.timeDimension7,
      timeDimension8: player.timeDimension8,
      eternityPoints: player.eternityPoints,
      eternities: player.eternities,
      thisEternity: player.thisEternity,
      bestEternity: player.bestEternity,
      eternityUpgrades: player.eternityUpgrades,
      epmult: player.epmult,
      epmultCost: player.epmultCost,
      totalTickGained: 0,
      offlineProd: player.offlineProd,
      offlineProdCost: player.offlineProdCost,
      extraDimPowerIncrease: player.extraDimPowerIncrease,
      dimPowerIncreaseCost: player.dimPowerIncreaseCost,
      challengeTarget: target,
      replicanti: player.replicanti,
      timestudy: player.timestudy,
      eternityChalls: player.eternityChalls,
      eternityChallGoal: player.eternityChallGoal,
      currentEternityChall: player.currentEternityChall,
      eternityChallUnlocked: player.eternityChallUnlocked,
      etercreq: player.etercreq,
      autoIP: player.autoIP,
      autoTime: player.autoTime,
      infMultBuyer: player.infMultBuyer,
      autoCrunchMode: player.autoCrunchMode,
      respec: player.respec,
      eternityBuyer: player.eternityBuyer,
      eterc8ids: player.eterc8ids,
      eterc8repl: player.eterc8repl,
      tickBoughtThisInf: {
        current: 0,
        pastResets: [{'resets': 0, 'bought': 0}]
      },
      dimlife: player.dimlife,
      dead: player.dead,
      dilation: player.dilation,
      why: player.why,
      galacticSacrifice: newGalacticDataOnInfinity(),
      options: player.options,
	  
	// for aarex modifications
	aarexModifications: {
		ngmX: 4,
		ngmm: 3,
		ngm4r: 1,
		newGame4MinusRespeccedVersion: newGame4MinusRespeccedVersion

	},
	
	tickspeedBoosts: 0,
	tdBoosts: 0,

    timeless: player.timeless,
    };
	
	resetTimeDimensions(1);
	if (player.currentChallenge == "challenge10" || player.currentChallenge == "postc4") {
        player.thirdCost = new Decimal(100)
        player.fourthCost = new Decimal(500)
        player.fifthCost = new Decimal(2500)
        player.sixthCost = new Decimal(2e4)
        player.seventhCost = new Decimal(2e5)
        player.eightCost = new Decimal(4e6)
    }
    if (player.currentChallenge == "challenge10" || player.currentChallenge == "postc4") player.costMultipliers = [new Decimal(1e3),new Decimal(5e3),new Decimal(1e4),new Decimal(1.2e4),new Decimal(1.8e4),new Decimal(2.6e4),new Decimal(3.2e4),new Decimal(4.2e4)];
    if (player.currentChallenge == "postc5") {
        player.eightAmount = new Decimal(1);
        player.eightBought = 1;
        player.resets = 4;
    }

    if (player.replicanti.unl) player.replicanti.amount = new Decimal(1)
    player.replicanti.galaxies = 0

    decreaseDimCosts();
    // even if we're in a challenge, apparently if it's challenge 2 we might have four resets anyway.
    setInitialDimensionPower();

    IPminpeak = new Decimal(0)
    if (player.currentChallenge.includes("post")) player.break = true
    if (player.achievements.includes("r36")) player.tickspeed = player.tickspeed.times(0.98);
    if (player.achievements.includes("r45")) player.tickspeed = player.tickspeed.times(0.98);
    if (player.achievements.includes("r66")) player.tickspeed = player.tickspeed.times(0.98);
    if (player.achievements.includes("r83")) player.tickspeed = player.tickspeed.times(Decimal.pow(0.95,player.galaxies));

    if (player.eternities < 30) {
        document.getElementById("secondRow").style.display = "none";
        document.getElementById("thirdRow").style.display = "none";
        document.getElementById("tickSpeed").style.visibility = "hidden";
        document.getElementById("tickSpeedMax").style.visibility = "hidden";
        document.getElementById("tickLabel").style.visibility = "hidden";
        document.getElementById("tickSpeedAmount").style.visibility = "hidden";
        document.getElementById("tickSpeedPurchases").style.visibility = "hidden";
        document.getElementById("fourthRow").style.display = "none";
    }
    document.getElementById("fifthRow").style.display= "none";
    document.getElementById("sixthRow").style.display= "none";
    document.getElementById("seventhRow").style.display= "none";
    document.getElementById("eightRow").style.display= "none";
    if (player.currentChallenge == "challenge12" || player.currentChallenge == "postc4" || player.currentChallenge == "postc8") document.getElementById("matter").style.display = "block";
    else document.getElementById("matter").style.display = "none";

    if (player.currentChallenge == "challenge13" || player.currentChallenge == "postc4" || player.currentChallenge === "postcngm3_3" || player.challenges.includes("postcngm3_3")) document.getElementById("chall13Mult").style.display = "block";
    else document.getElementById("chall13Mult").style.display = "none";

    if (inQuickResetChallenge()) document.getElementById("quickReset").style.display = "inline-block";
    else document.getElementById("quickReset").style.display = "none";

    showTab('dimensions');
    updateChallenges();
    if (player.challenges.includes("challenge1")) player.money = new Decimal(100)
    if (player.achievements.includes("r37")) player.money = new Decimal(1000);
    if (player.achievements.includes("r54")) player.money = new Decimal(2e5);
    if (player.achievements.includes("r55")) player.money = new Decimal(1e10);
    if (player.achievements.includes("r78")) player.money = new Decimal(1e25);
    showTab("dimensions")
    try {
        kongregate.stats.submit('Infinitied', getInfinitied());
        kongregate.stats.submit('Fastest Infinity time', Math.floor(player.bestInfinityTime / 10))
    } catch (err) {console.log("Couldn't load Kongregate API")}

    if (player.infinitied >= 10) giveAchievement("That's a lot of infinites");

    document.getElementById("replicantireset").innerHTML = "Reset replicanti amount, but get a free galaxy<br>"+player.replicanti.galaxies + " replicated galaxies created."

    resetInfDimensions();
    player.tickspeed = player.tickspeed.times(Decimal.pow(getTickSpeedMultiplier(), player.totalTickGained))
    player.postC3Reward = player.postC3Reward.times(Decimal.pow(getPostC3RewardMult(), player.totalTickGained))
    updateTickSpeed();

    if (player.resets == 0 && player.currentChallenge == "") {
        if (player.infinityUpgrades.includes("skipReset1")) player.resets++;
        if (player.infinityUpgrades.includes("skipReset2")) player.resets++;
        if (player.infinityUpgrades.includes("skipReset3")) player.resets++;
        if (player.infinityUpgrades.includes("skipResetGalaxy")) {
            player.resets++;
            if (player.galaxies == 0) player.galaxies = 1
        }
		if (player.resets > 0)player.tickspeedBoosts = player.tdBoosts = Math.pow(2,player.resets);
    }
    if (player.currentChallenge.includes("post") && player.currentEternityChall !== "") giveAchievement("I wish I had gotten 7 eternities")
    Marathon2 = 0;
}
}

function unlockEChall(idx) {
    if (player.eternityChallUnlocked == 0) {
        player.eternityChallUnlocked = idx
        document.getElementById("eterc"+player.eternityChallUnlocked+"div").style.display = "inline-block"
        if (!justImported) showTab("challenges")
        if (!justImported) showChallengesTab("eternitychallenges")
        if (idx !== 12 && idx !== 13) player.etercreq = idx
    }
    updateEternityChallenges()
    updateTimeStudyButtons()
}

function ECTimesCompleted(name) {
    if (player.eternityChalls[name] === undefined) return 0
    else return player.eternityChalls[name]
}

function canUnlockEC(idx, cost, study, study2) {
	//return false;
    study2 = (study2 !== undefined) ? study2 : 0;
    if (player.eternityChallUnlocked !== 0) return false
    if (!player.timestudy.studies.includes(study) && (player.study2 == 0 || !player.timestudy.studies.includes(study2))) return false
    if (player.timestudy.theorem < cost) return false
    if (player.etercreq == idx && idx !== 11 && idx !== 12) return true

    switch(idx) {
        case 1:
        if (player.eternities >= 20000+(ECTimesCompleted("eterc1")*20000)) return true
        break;

        case 2:
        if (player.totalTickGained >= 1300+(ECTimesCompleted("eterc2")*150)) return true
        break;

        case 3:
        if (player.eightAmount.gte(17300+(ECTimesCompleted("eterc3")*1250))) return true
        break;

        case 4:
        if (1e8 + (ECTimesCompleted("eterc4")*5e7) <= getInfinitied()) return true
        break;

        case 5:
        if (52 + (Math.pow(ECTimesCompleted("eterc5"),0.72)*3) <= player.galaxies) return true
        break;

        case 6:
        if (40 + (ECTimesCompleted("eterc6")*5) <= player.replicanti.galaxies) return true
        break;

        case 7:
        if (player.money.gte(new Decimal("1e500000").times(new Decimal("1e300000").pow(ECTimesCompleted("eterc7"))))) return true
        break;

        case 8:
        if (player.infinityPoints.gte(new Decimal("1e4000").times(new Decimal("1e1000").pow(ECTimesCompleted("eterc8"))))) return true
        break;

        case 9:
        if (player.infinityPower.gte(new Decimal("1e17500").times(new Decimal("1e2000").pow(ECTimesCompleted("eterc9"))))) return true
        break;

        case 10:
        if (player.eternityPoints.gte(new Decimal("1e100").times(new Decimal("1e20").pow(ECTimesCompleted("eterc10"))))) return true
        break;

        case 11:
        if (player.timestudy.studies.includes(71) && !player.timestudy.studies.includes(72) && !player.timestudy.studies.includes(73)) return true
        break;

        case 12:
        if (player.timestudy.studies.includes(73) && !player.timestudy.studies.includes(71) && !player.timestudy.studies.includes(72)) return true
        break;
    }
}

function updateECUnlockButtons() {
    if (canUnlockEC(1, 30, 171)) {
        document.getElementById("ec1unl").className = "eternitychallengestudy"
    } else {
        document.getElementById("ec1unl").className = "eternitychallengestudylocked"
    }

    if (canUnlockEC(2, 35, 171)) {
        document.getElementById("ec2unl").className = "eternitychallengestudy"
    } else {
        document.getElementById("ec2unl").className = "eternitychallengestudylocked"
    }

    if (canUnlockEC(3, 40, 171)) {
        document.getElementById("ec3unl").className = "eternitychallengestudy"
    } else {
        document.getElementById("ec3unl").className = "eternitychallengestudylocked"
    }

    if (canUnlockEC(4, 70, 143)) {
        document.getElementById("ec4unl").className = "eternitychallengestudy"
    } else {
        document.getElementById("ec4unl").className = "eternitychallengestudylocked"
    }

    if (canUnlockEC(5, 130, 42)) {
        document.getElementById("ec5unl").className = "eternitychallengestudy"
    } else {
        document.getElementById("ec5unl").className = "eternitychallengestudylocked"
    }

    if (canUnlockEC(6, 85, 121)) {
        document.getElementById("ec6unl").className = "eternitychallengestudy"
    } else {
        document.getElementById("ec6unl").className = "eternitychallengestudylocked"
    }

    if (canUnlockEC(7, 115, 111)) {
        document.getElementById("ec7unl").className = "eternitychallengestudy"
    } else {
        document.getElementById("ec7unl").className = "eternitychallengestudylocked"
    }

    if (canUnlockEC(8, 115, 123)) {
        document.getElementById("ec8unl").className = "eternitychallengestudy"
    } else {
        document.getElementById("ec8unl").className = "eternitychallengestudylocked"
    }

    if (canUnlockEC(9, 415, 151)) {
        document.getElementById("ec9unl").className = "eternitychallengestudy"
    } else {
        document.getElementById("ec9unl").className = "eternitychallengestudylocked"
    }

    if (canUnlockEC(10, 550, 181)) {
        document.getElementById("ec10unl").className = "eternitychallengestudy"
    } else {
        document.getElementById("ec10unl").className = "eternitychallengestudylocked"
    }

    if (canUnlockEC(11, 1, 231, 232)) {
        document.getElementById("ec11unl").className = "eternitychallengestudy"
    } else {
        document.getElementById("ec11unl").className = "eternitychallengestudylocked"
    }

    if (canUnlockEC(12, 1, 233, 234)) {
        document.getElementById("ec12unl").className = "eternitychallengestudy"
    } else {
        document.getElementById("ec12unl").className = "eternitychallengestudylocked"
    }

    if (player.eternityChallUnlocked !== 0 )document.getElementById("ec"+player.eternityChallUnlocked+"unl").className = "eternitychallengestudybought"
}

document.getElementById("ec1unl").onclick = function() {
    if (canUnlockEC(1, 30, 171)) {
        unlockEChall(1)
        player.timestudy.theorem -= 30
        updateTheoremButtons()
        updateTimeStudyButtons()
        drawStudyTree()
    }
}

document.getElementById("ec2unl").onclick = function() {
    if (canUnlockEC(2, 35, 171)) {
        unlockEChall(2)
        player.timestudy.theorem -= 35
        updateTheoremButtons()
        updateTimeStudyButtons()
        drawStudyTree()
    }
}

document.getElementById("ec3unl").onclick = function() {
    if (canUnlockEC(3, 40, 171)) {
        unlockEChall(3)
        player.timestudy.theorem -= 40
        updateTheoremButtons()
        updateTimeStudyButtons()
        drawStudyTree()
    }
}

document.getElementById("ec4unl").onclick = function() {
    if (canUnlockEC(4, 70, 143)) {
        unlockEChall(4)
        player.timestudy.theorem -= 70
        updateTheoremButtons()
        updateTimeStudyButtons()
        drawStudyTree()
    }
}

document.getElementById("ec5unl").onclick = function() {
    if (canUnlockEC(5, 130, 42)) {
        unlockEChall(5)
        player.timestudy.theorem -= 130
        updateTheoremButtons()
        updateTimeStudyButtons()
        drawStudyTree()
    }
}

document.getElementById("ec6unl").onclick = function() {
    if (canUnlockEC(6, 85, 121)) {
        unlockEChall(6)
        player.timestudy.theorem -= 85
        updateTheoremButtons()
        updateTimeStudyButtons()
        drawStudyTree()
    }
}

document.getElementById("ec7unl").onclick = function() {
    if (canUnlockEC(7, 115, 111)) {
        unlockEChall(7)
        player.timestudy.theorem -= 115
        updateTheoremButtons()
        updateTimeStudyButtons()
        drawStudyTree()
    }
}

document.getElementById("ec8unl").onclick = function() {
    if (canUnlockEC(8, 115, 123)) {
        unlockEChall(8)
        player.timestudy.theorem -= 115
        updateTheoremButtons()
        updateTimeStudyButtons()
        drawStudyTree()
    }
}

document.getElementById("ec9unl").onclick = function() {
    if (canUnlockEC(9, 415, 151)) {
        unlockEChall(9)
        player.timestudy.theorem -= 415
        updateTheoremButtons()
        updateTimeStudyButtons()
        drawStudyTree()
    }
}

document.getElementById("ec10unl").onclick = function() {
    if (canUnlockEC(10, 550, 181)) {
        unlockEChall(10)
        player.timestudy.theorem -= 550
        updateTheoremButtons()
        updateTimeStudyButtons()
        drawStudyTree()
    }
}

document.getElementById("ec11unl").onclick = function() {
    if (canUnlockEC(11, 1, 231, 232)) {
        unlockEChall(11)
        player.timestudy.theorem -= 1
        updateTheoremButtons()
        updateTimeStudyButtons()
        drawStudyTree()
    }
}

document.getElementById("ec12unl").onclick = function() {
    if (canUnlockEC(12, 1, 233, 234)) {
        unlockEChall(12)
        player.timestudy.theorem -= 1
        updateTheoremButtons()
        updateTimeStudyButtons()
        drawStudyTree()
    }
}

function getECGoal(name){
	if(name=="eterc1")return new Decimal(["1e800","1e850","1e900","1e950","1e1000","1e1050"][ECTimesCompleted(name)]);
	if(name=="eterc2")return new Decimal(["1e1400","1e2300","1e3200","1e4100","1e5000","1e5900"][ECTimesCompleted(name)]);
	if(name=="eterc3")return new Decimal(["1e800","1e1400","1e2000","1e2600","1e3200","1e3800"][ECTimesCompleted(name)]);
	if(name=="eterc4")return new Decimal(["1e3000","1e3600","1e4200","1e4800","1e5400","1e6000"][ECTimesCompleted(name)]);
	if(name=="eterc5")return new Decimal(["1e2400","1e3300","1e4200","1e5100","1e6000","1e6900"][ECTimesCompleted(name)]);
	if(name=="eterc6")return new Decimal(["1e1800","1e2300","1e2800","1e3300","1e3800","1e4300"][ECTimesCompleted(name)]);
	if(name=="eterc7")return new Decimal(["1e3500","1e6500","1e7500","1e9500","1e11500","1e13500"][ECTimesCompleted(name)]);
	if(name=="eterc8")return new Decimal(["1e4400","1e5400","1e6400","1e7400","1e8400","1e9400"][ECTimesCompleted(name)]);
	if(name=="eterc9")return new Decimal(["1e5700","1e7800","1e9900","1e12000","1e14100","1e16200"][ECTimesCompleted(name)]);
	if(name=="eterc10")return new Decimal("1e5500");
	if(name=="eterc11")return new Decimal(["1e5000","1e99999999"][ECTimesCompleted(name)]);
	if(name=="eterc12")return new Decimal(["1e56000","1e99999999"][ECTimesCompleted(name)]);
	return new Decimal("1e99999999");
}

function startEternityChallenge(name) {
    if (player.eternityChallUnlocked == 0 || parseInt(name.split("c")[1]) !== player.eternityChallUnlocked) return
if(player.timeless.active || player.dilation.active)return;
    if((player.options.challConf) || name == "" ? true :  (confirm("You will start over with just your time studies, eternity upgrades and achievements. You need to reach a set IP with special conditions."))) {
        player = {
            money: new Decimal(10),
            tickSpeedCost: new Decimal(1000),
            tickspeed: new Decimal(10000),
            firstCost: new Decimal(10),
            secondCost: new Decimal(100),
            thirdCost: new Decimal(10000),
            fourthCost: new Decimal(1000000),
            fifthCost: new Decimal(1e9),
            sixthCost: new Decimal(1e13),
            seventhCost: new Decimal(1e18),
            eightCost: new Decimal(1e24),
            firstAmount: new Decimal(0),
            secondAmount: new Decimal(0),
            thirdAmount: new Decimal(0),
            fourthAmount: new Decimal(0),
            firstBought: 0,
            secondBought: 0,
            thirdBought: 0,
            fourthBought: 0,
            firstTotalBought: 0,
            secondTotalBought: 0,
            thirdTotalBought: 0,
            fourthTotalBought: 0,
            fifthAmount: new Decimal(0),
            sixthAmount: new Decimal(0),
            seventhAmount: new Decimal(0),
            eightAmount: new Decimal(0),
            fifthBought: 0,
            sixthBought: 0,
            seventhBought: 0,
            eightBought: 0,
            fifthTotalBought: 0,
            sixthTotalBought: 0,
            seventhTotalBought: 0,
            eightTotalBought: 0,
            firstPow: new Decimal(1),
            secondPow: new Decimal(1),
            thirdPow: new Decimal(1),
            fourthPow: new Decimal(1),
            fifthPow: new Decimal(1),
            sixthPow: new Decimal(1),
            seventhPow: new Decimal(1),
            eightPow: new Decimal(1),
            sacrificed: new Decimal(0),
            achievements: player.achievements,
            challenges: getKeptChallenges(),
            currentChallenge: "",
            infinityUpgrades: player.infinityUpgrades,
            infinityPoints: new Decimal(0),
            infinitied: 0,
            infinitiedBank: player.infinitiedBank,
            totalTimePlayed: player.totalTimePlayed,
            bestInfinityTime: 9999999999,
            thisInfinityTime: 0,
            resets: (player.eternities > 2) ? 4 : 0,
            galaxies: (player.eternities > 2) ? 1 : 0,
            tickDecrease: 0.9,
            totalmoney: player.totalmoney,
            interval: null,
            lastUpdate: player.lastUpdate,
            achPow: player.achPow,
            autobuyers: player.autobuyers,
            partInfinityPoint: 0,
            partInfinitied: 0,
            break: player.break,
            costMultipliers: [new Decimal(1e3), new Decimal(1e4), new Decimal(1e5), new Decimal(1e6), new Decimal(1e8), new Decimal(1e10), new Decimal(1e12), new Decimal(1e15)],
            tickspeedMultiplier: new Decimal(10),
            chall2Pow: 1,
            chall3Pow: new Decimal(0.01),
            newsArray: player.newsArray,
            matter: new Decimal(0),
            chall11Pow: new Decimal(1),
            challengeTimes: player.challengeTimes,
            infchallengeTimes: player.infchallengeTimes,
            lastTenRuns: [[600*60*24*31, new Decimal(1)], [600*60*24*31, new Decimal(1)], [600*60*24*31, new Decimal(1)], [600*60*24*31, new Decimal(1)], [600*60*24*31, new Decimal(1)], [600*60*24*31, new Decimal(1)], [600*60*24*31, new Decimal(1)], [600*60*24*31, new Decimal(1)], [600*60*24*31, new Decimal(1)], [600*60*24*31, new Decimal(1)]],
            lastTenEternities: player.lastTenEternities,
            infMult: new Decimal(1),
            infMultCost: new Decimal(10),
            tickSpeedMultDecrease: player.eternities > 18 ? player.tickSpeedMultDecrease : 10,
            tickSpeedMultDecreaseCost: player.eternities > 18 ? player.tickSpeedMultDecreaseCost : 3e6,
            dimensionMultDecrease: player.eternities > 18 ? player.dimensionMultDecrease : 10,
            dimensionMultDecreaseCost: player.eternities > 18 ? player.dimensionMultDecreaseCost : 1e8,
            version: player.version,
            postChallUnlocked: (player.achievements.includes("r133")) ? 8 : 0,
            postC6Tier: 1,
            postC3Reward: new Decimal(1),
            overXGalaxies: player.overXGalaxies,
            spreadingCancer: player.spreadingCancer,
            infDimensionsUnlocked: [false, false, false, false, false, false, false, false],
            infinityPower: new Decimal(1),
            infinityDimension1 : {
                cost: new Decimal(1e8),
                amount: new Decimal(0),
                bought: 0,
                power: new Decimal(1),
                baseAmount: 0
            },
            infinityDimension2 : {
                cost: new Decimal(1e9),
                amount: new Decimal(0),
                bought: 0,
                power: new Decimal(1),
                baseAmount: 0
            },
            infinityDimension3 : {
                cost: new Decimal(1e10),
                amount: new Decimal(0),
                bought: 0,
                power: new Decimal(1),
                baseAmount: 0
            },
            infinityDimension4 : {
                cost: new Decimal(1e20),
                amount: new Decimal(0),
                bought: 0,
                power: new Decimal(1),
                baseAmount: 0
            },
            infinityDimension5 : {
                cost: new Decimal(1e140),
                amount: new Decimal(0),
                bought: 0,
                power: new Decimal(1),
                baseAmount: 0
            },
            infinityDimension6 : {
                cost: new Decimal(1e200),
                amount: new Decimal(0),
                bought: 0,
                power: new Decimal(1),
                baseAmount: 0
            },
            infinityDimension7 : {
                cost: new Decimal(1e250),
                amount: new Decimal(0),
                bought: 0,
                power: new Decimal(1),
                baseAmount: 0
            },
            infinityDimension8 : {
                cost: new Decimal(1e280),
                amount: new Decimal(0),
                bought: 0,
                power: new Decimal(1),
                baseAmount: 0
            },
            infDimBuyers: player.infDimBuyers,
            timeShards: new Decimal(0),
            tickThreshold: new Decimal(1),
            totalTickGained: 0,
            timeDimension1: player.timeDimension1,
            timeDimension2: player.timeDimension2,
            timeDimension3: player.timeDimension3,
            timeDimension4: player.timeDimension4,
            timeDimension5: player.timeDimension5,
            timeDimension6: player.timeDimension6,
            timeDimension7: player.timeDimension7,
            timeDimension8: player.timeDimension8,
            eternityPoints: player.eternityPoints,
            eternities: player.eternities+1,
            thisEternity: 0,
            bestEternity: player.bestEternity,
            eternityUpgrades: player.eternityUpgrades,
            epmult: player.epmult,
            epmultCost: player.epmultCost,
            totalTickGained: 0,
            offlineProd: player.eternities > 18 ? player.offlineProd : 0,
            offlineProdCost: player.eternities > 18 ? player.offlineProdCost : 1e7,
            extraDimPowerIncrease: player.eternities > 18 ? player.extraDimPowerIncrease : 0,
            dimPowerIncreaseCost: player.eternities > 18 ? player.dimPowerIncreaseCost : new Decimal(1e3),
            challengeTarget: 0,
            replicanti: {
                amount: player.eternities > 48 ? 1 : 0,
                unl: player.eternities > 48 ? true : false,
                chance: 0.01,
                chanceCost: new Decimal(1e90),
                interval: 1000,
                intervalCost: new Decimal(1e80),
                gal: 0,
                galaxies: 0,
                galCost: new Decimal(1e110),
                galaxybuyer: (player.eternities > 1) ? player.replicanti.galaxybuyer : undefined,
                auto: player.replicanti.auto
            },
            timestudy: player.timestudy,
            eternityChalls: player.eternityChalls,
            eternityChallGoal: getECGoal(name),
            currentEternityChall: name,
            eternityChallUnlocked: player.eternityChallUnlocked,
            etercreq: player.etercreq,
            autoIP: new Decimal(0),
            autoTime: 1e300,
            infMultBuyer: player.infMultBuyer,
            autoCrunchMode: player.autoCrunchMode,
            respec: player.respec,
            eternityBuyer: player.eternityBuyer,
            eterc8ids: 50,
            eterc8repl: 40,
            tickBoughtThisInf: {
              current: 0,
              pastResets: [{'resets': 0, 'bought': 0}]
            },
            dimlife: true,
            dead: true,
            dilation: {
                studies: player.dilation.studies,
                active: false,
                tachyonParticles: player.dilation.tachyonParticles,
                dilatedTime: player.dilation.dilatedTime,
                totalTachyonParticles: player.dilation.totalTachyonParticles,
                nextThreshold: player.dilation.nextThreshold,
                freeGalaxies: player.dilation.freeGalaxies,
                upgrades: player.dilation.upgrades,
                rebuyables: player.dilation.rebuyables
            },
            why: player.why,
	          galacticSacrifice: {
              galaxyPoints: new Decimal(0),
              last: Date.now(),
              times: 0,
              upgrades: []
            },
            options: player.options,
			
			
	// for aarex modifications
	aarexModifications: {
		ngmX: 4,
		ngmm: 3,
		ngm4r: 1,
		newGame4MinusRespeccedVersion: newGame4MinusRespeccedVersion

	},
	
	tickspeedBoosts: 0,
	tdBoosts: 0,

    timeless: player.timeless,
	          galacticSacrifice: player.timeless.upgrades.includes(27)?player.galacticSacrifice:{
              galaxyPoints: new Decimal(0),
              last: Date.now(),
              times: 0,
              upgrades: []
            },
        };

        if (player.replicanti.unl) player.replicanti.amount = new Decimal(1)
        player.replicanti.galaxies = 0
        if (player.achievements.includes("r36")) player.tickspeed = player.tickspeed.times(0.98);
        if (player.achievements.includes("r45")) player.tickspeed = player.tickspeed.times(0.98);
        if (player.eternities < 30) {
            document.getElementById("secondRow").style.display = "none";
            document.getElementById("thirdRow").style.display = "none";
            document.getElementById("tickSpeed").style.visibility = "hidden";
            document.getElementById("tickSpeedMax").style.visibility = "hidden";
            document.getElementById("tickLabel").style.visibility = "hidden";
            document.getElementById("tickSpeedAmount").style.visibility = "hidden";
            document.getElementById("tickSpeedPurchases").style.visibility = "hidden";
            document.getElementById("fourthRow").style.display = "none";
        }
        document.getElementById("fifthRow").style.display = "none";
        document.getElementById("sixthRow").style.display = "none";
        document.getElementById("seventhRow").style.display = "none";
        document.getElementById("eightRow").style.display = "none";
        document.getElementById("matter").style.display = "none";
        if (player.challenges.includes("postcngm3_3")) document.getElementById("chall13Mult").style.display = "block";
        else document.getElementById("chall13Mult").style.display = "none";
        document.getElementById("quickReset").style.display = "none";
        var autobuyers = document.getElementsByClassName('autoBuyerDiv')
        if (player.eternities < 2) {
            for (var i=0; i<autobuyers.length;i++) autobuyers.item(i).style.display = "none"
            document.getElementById("buyerBtnDimBoost").style.display = "inline-block"
            document.getElementById("buyerBtnGalaxies").style.display = "inline-block"
            document.getElementById("buyerBtnInf").style.display = "inline-block"
            document.getElementById("buyerBtnTickSpeed").style.display = "inline-block"
        }
        updateAutobuyers();
        if (player.achievements.includes("r37")) player.money = new Decimal(1000);
        if (player.achievements.includes("r54")) player.money = new Decimal(2e5);
        if (player.achievements.includes("r55")) player.money = new Decimal(1e10);
        if (player.achievements.includes("r78")) player.money = new Decimal(1e25);
        if (player.achievements.includes("r104")) player.infinityPoints = new Decimal(2e25);
        resetInfDimensions();
        updateChallenges();
        updateChallengeTimes()
        updateLastTenRuns()
        updateLastTenEternities()
        var infchalls = Array.from(document.getElementsByClassName('infchallengediv'))
        for (var i = 0; i< infchalls.length; i++) infchalls[i].style.display = "none"
        IPminpeak = new Decimal(0)
        EPminpeak = new Decimal(0)
        updateMilestones()
        resetTimeDimensions()
        if (player.eternities < 20) player.autobuyers[9].bulk = 1
        if (player.eternities < 20) document.getElementById("bulkDimboost").value = player.autobuyers[9].bulk
        if (player.eternities < 50) {
            document.getElementById("replicantidiv").style.display="none"
            document.getElementById("replicantiunlock").style.display="inline-block"
        }
        try {
            kongregate.stats.submit('Eternities', player.eternities);
        } catch (err) {console.log("Couldn't load Kongregate API")}
        if (player.eternities > 2 && player.replicanti.galaxybuyer === undefined) player.replicanti.galaxybuyer = false
        document.getElementById("infinityPoints1").innerHTML = "You have <span class=\"IPAmount1\">"+shortenDimensions(player.infinityPoints)+"</span> Infinity points."
        document.getElementById("infinityPoints2").innerHTML = "You have <span class=\"IPAmount2\">"+shortenDimensions(player.infinityPoints)+"</span> Infinity points."
        if (player.eternities < 2) document.getElementById("break").textContent = "BREAK INFINITY"
        document.getElementById("replicantireset").innerHTML = "Reset replicanti amount, but get a free galaxy<br>"+player.replicanti.galaxies + " replicated galaxies created."
        document.getElementById("eternitybtn").style.display = player.infinityPoints.gte(player.eternityChallGoal) ? "inline-block" : "none"
if(player.timeless.active)document.getElementById("eternitybtn").style.display = "inline-block"
        document.getElementById("eternityPoints2").style.display = "inline-block"
        document.getElementById("eternitystorebtn").style.display = "inline-block"
        document.getElementById("infiMult").innerHTML = "Multiply infinity points from all sources by "+getIPMultMultiplier().toFixed(2)+" <br>currently: "+shorten(getIPMult()) +"x<br>Cost: "+shortenCosts(getIPMult())+" IP"
        updateEternityUpgrades()
        document.getElementById("totaltickgained").textContent = "You've gained "+player.totalTickGained.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",")+" tickspeed upgrades."
		if (player.achievements.includes("r105"))document.getElementById("totaltickgained").textContent += " 'Infinite Time' multiplier: "+shorten(player.postC3Reward.pow(infiniteTimeStrength()))+".";
        if (player.tickspeedBoosts)document.getElementById("totaltickgained").textContent += " Tickspeed Boosts are reducing timeshard requirement by "+shorten(Math.pow(player.tickspeedBoosts,0.9)*100*Math.max(Math.sqrt(player.galacticSacrifice.galaxyPoints.max(1).log10()) / 3,1))+" tickspeed upgrades";
        updateTickSpeed();
        playerInfinityUpgradesOnEternity()
        document.getElementById("eternityPoints2").innerHTML = "You have <span class=\"EPAmount2\">"+shortenDimensions(player.eternityPoints)+"</span> Eternity point"+((player.eternityPoints.eq(1)) ? "." : "s.")+(player.eternities >= 1 ?("<br>Eternity point gain is dilated after "+shorten(Decimal.pow(10,getDilationStart()))+".<br>Multiplier to EP gain pre-dilation based on eternities: "+shorten(EternitiesEPMult().div(3))):"");
                if (player.achievements.includes("r102"))document.getElementById("eternityPoints2").innerHTML += "<br>Multiplier to EP gain post-dilation based on eternities: "+shorten(player.eternities+1)
		updateEternityChallenges()
        Marathon2 = 0;


    }
}

function getUnspentIPBonus () {
  // starts out really strong, then becomes balanced but noticable (given the existance of dilation)
  let x = player.infinityPoints;
  let y = Math.max(Decimal.min(8, Math.pow(x.max(1).log(10), 1 / 3) * 3), 1);
  return x.pow(y).plus(1);
}

function startDilatedEternity() {
    if (!player.dilation.studies.includes(1)) return
    clearInterval(gameLoopIntervalId);
    if (player.dilation.active) {
        eternity(true)
        setTimeout(function() {
            gameLoopIntervalId = setInterval(gameLoop, player.options.updateRate);
        }, 250)
        return
    }
    var add=""
    if(player.dilation.tachyonParticles!=0)add+="/DT Gain";
    if(player.dilation.studies.includes(6))add+="/MD Mult";
    if (!confirm("Dilating time will start a new eternity, and all first dilation effects (ND Mult/ID Mult/TD Mult/Tickspeed/Infinity Power/Timeshards/EP Gain"+add+") are applied twice. If you can eternity while dilated, you'll be rewarded with tachyon particles based on your antimatter and tachyon particles.")) {
        setTimeout(function() {
            gameLoopIntervalId = setInterval(gameLoop, player.options.updateRate);
        }, 250)
        return
    }
    giveAchievement("I told you already, time is relative")
    eternity(true)
    player.dilation.active = true;
    var totalMult = 1
    var currentMult = 1
    var infinitiedMult = 1
    var achievementMult = 1
    var challengeMult = 1
    var unspentBonus = 1
    var postc10Mult = new Decimal(0)
    var mult18 = new Decimal(1)
    var ec10bonus = new Decimal(1)
    var timeMultNum = 1
    var timeMultNum2 = 1
    setTimeout(function() {
        gameLoopIntervalId = setInterval(gameLoop, player.options.updateRate);
    }, 250)
}


function enterTimeless() {
    if (!player.eternityUpgrades.includes(7)) return
    clearInterval(gameLoopIntervalId);
    if (player.timeless.active) {
        eternity(true)
        setTimeout(function() {
            gameLoopIntervalId = setInterval(gameLoop, player.options.updateRate);
        }, 250)
        return
    }
    var add=""
    if (!confirm("Entering Timeless will start a new eternity, clear your GP, and you can't buy TDs and tickspeed upgrades with AM, you are stuck in IC3 (tickspeed multiplier is 1x), galaxies are 90% weaker, and some galaxy upgrades are nerfed. When exiting Timeless, you will gain Timeless Shards based on Timeshards.")) {
        setTimeout(function() {
            gameLoopIntervalId = setInterval(gameLoop, player.options.updateRate);
        }, 250)
        return
    }
    giveAchievement("Is time relative?")
    eternity(true)
    player.timeless.active = true;
    if(!player.timeless.upgrades.includes(6))player.galacticSacrifice.galaxyPoints = new Decimal(1);
    var totalMult = 1
    var currentMult = 1
    var infinitiedMult = 1
    var achievementMult = 1
    var challengeMult = 1
    var unspentBonus = 1
    var postc10Mult = new Decimal(0)
    var mult18 = new Decimal(1)
    var ec10bonus = new Decimal(1)
    var timeMultNum = 1
    var timeMultNum2 = 1
    setTimeout(function() {
        gameLoopIntervalId = setInterval(gameLoop, player.options.updateRate);
    }, 250)
}

function unlockDilation() {
    if (player.dilation.studies.includes(1)) return
    if (player.timestudy.theorem < 5000) return
    if (ECTimesCompleted("eterc12") !== 5) return
    if (ECTimesCompleted("eterc11") !== 5) return
    player.timestudy.theorem -= 5000
    document.getElementById("dilationunlock").className = "dilationupgbought"
    updateTimeStudyButtons()
    showEternityTab("dilation")
    document.getElementById("dilationunlock").innerHTML = "Unlock time dilation<span>Cost: 5000 Time Theorems"
}


 const TIMELESS_UPG_COSTS = [null, [10, 10],[1e3,100],[100,20],20,
 100,1000,1e4,5e4,
 1e8,1e5,1e10,1e9,
 1e13,1e11,1e12,1e14,
 3e14,5e14,1e15,3e15,
 1e19,1e20,3e20,1e21,
 2e22,5e22,1e23,5e23,
 1e26,1e27,1e29,1e31,4e34,1e36,1e55,
 ]
 const TOTAL_TIMELESS_UPGS = 35
/**
 *
 * @param {Name of the ugrade} id
 * @param {Cost of the upgrade} cost
 * @param {Cost increase for the upgrade, only for rebuyables} costInc
 *
 * id 1-3 are rebuyables
 *
 * id 2 resets your dilated time and free galaxies
 *
 */

											
 const DIL_UPG_COSTS = [null, [1e5, 10], [1e6, 100], [1e7, 20],
                              5e6,        1e9,         5e7,
                              2e12,        1e10,         1e11,
                                            1e15]


function buyTimelessUpgrade(id, costInc) {
    if (id > 3) { // Not rebuyable
        if (player.timeless.points < TIMELESS_UPG_COSTS[id]) return // Not enough dilated time
        if (player.timeless.upgrades.includes(id)) return // Has the upgrade
        player.timeless.points = player.timeless.points.minus(TIMELESS_UPG_COSTS[id])
        player.timeless.upgrades.push(id)
    } else { // Is rebuyable
        let upgAmount = player.timeless.rebuyables[id] = player.timeless.rebuyables[id]||0;
        let realCost = new Decimal(TIMELESS_UPG_COSTS[id][0]).times( Decimal.pow(TIMELESS_UPG_COSTS[id][1], (upgAmount)) )
		if(player.timeless.upgrades.includes(33) && id==3)realCost=realCost.pow(0.5);
		if(player.timeless.upgrades.includes(35) && id==3)realCost=realCost.pow(0.5);
        if (player.timeless.points.lt(realCost)) return

        player.timeless.points = player.timeless.points.minus(realCost)
        player.timeless.rebuyables[id] += 1
		if(id==3)player.timestudy.theorem++;
    }

    updateDilationUpgradeCosts()
    updateDilationUpgradeButtons()
    updateTimeStudyButtons()
}

											
function buyDilationUpgrade(id, costInc) {
    if (id > 3) { // Not rebuyable
        if (player.dilation.dilatedTime < DIL_UPG_COSTS[id]) return // Not enough dilated time
        if (player.dilation.upgrades.includes(id)) return // Has the upgrade
        player.dilation.dilatedTime = player.dilation.dilatedTime.minus(DIL_UPG_COSTS[id])
        player.dilation.upgrades.push(id)
        if (id == 4) player.dilation.freeGalaxies *= 2 // Double the current galaxies
    } else { // Is rebuyable
        let upgAmount = player.dilation.rebuyables[id];
        let realCost = new Decimal(DIL_UPG_COSTS[id][0]).times( Decimal.pow(DIL_UPG_COSTS[id][1], (upgAmount)) )
        if (player.dilation.dilatedTime.lt(realCost)) return

        player.dilation.dilatedTime = player.dilation.dilatedTime.minus(realCost)
        player.dilation.rebuyables[id] += 1
        if (id == 2) {
            player.dilation.dilatedTime = new Decimal(0)
            player.dilation.nextThreshold = new Decimal(1000)
            player.dilation.freeGalaxies = 0
        }
    }

    updateDilationUpgradeCosts()
    updateDilationUpgradeButtons()
    updateTimeStudyButtons()
}

function updateDilationUpgradeButtons() {
    for (var i = 1; i <= TOTAL_TIMELESS_UPGS; i++) {
		if(!document.getElementById("timeless"+i))continue;
        if (i <= 3) {
            document.getElementById("timeless"+i).className = ( new Decimal(TIMELESS_UPG_COSTS[i][0]).times(Decimal.pow(TIMELESS_UPG_COSTS[i][1],(player.timeless.rebuyables[i]||0))).gt(player.timeless.points) ) ? "timestudylocked" : "timestudy";
			let power=1;
			if(player.timeless.upgrades.includes(33))power=power*0.5;
			if(player.timeless.upgrades.includes(35))power=power*0.5;
			if(i==3)document.getElementById("timeless"+i).className = ( new Decimal(TIMELESS_UPG_COSTS[i][0]).times(Decimal.pow(TIMELESS_UPG_COSTS[i][1],(player.timeless.rebuyables[i]||0))).pow(power).gt(player.timeless.points) ) ? "timestudylocked" : "timestudy";
		} else if (player.timeless.upgrades.includes(i)) {
            document.getElementById("timeless"+i).className = "timestudybought"
        } else {
            document.getElementById("timeless"+i).className = ( TIMELESS_UPG_COSTS[i] > player.timeless.points ) ? "timestudylocked" : "timestudy";
        }
    }
	
    for (var i = 1; i <= 10; i++) {
        if (i <= 3) {
            document.getElementById("dil"+i).className = ( new Decimal(DIL_UPG_COSTS[i][0]).times(Decimal.pow(DIL_UPG_COSTS[i][1],(player.dilation.rebuyables[i]))).gt(player.dilation.dilatedTime) ) ? "dilationupgrebuyablelocked" : "dilationupgrebuyable";
        } else if (player.dilation.upgrades.includes(i)) {
            document.getElementById("dil"+i).className = "dilationupgbought"
        } else {
            document.getElementById("dil"+i).className = ( DIL_UPG_COSTS[i] > player.dilation.dilatedTime ) ? "dilationupglocked" : "dilationupg";
        }
    }
    document.getElementById("timeless4desc").textContent = "Currently: "+shortenMoney(TLPU4())+"x"
    document.getElementById("timeless5desc").textContent = "Currently: "+shortenMoney(TLPU5())+"x"
    document.getElementById("timeless10desc").textContent = "Currently: "+shortenMoney(player.galacticSacrifice.galaxyPoints.add(10).log10())+"x TLP, "+shortenMoney(player.timeless.points.pow(5))+"x GP"
    document.getElementById("timeless21desc").textContent = "Currently: "+shortenMoney(TLPU21())+"x"
    document.getElementById("timeless23desc").textContent = "Currently: "+shortenMoney(player.timeShards.add(1).sqrt())+"x"
	document.getElementById("timeless26desc").textContent = "Currently: ^"+shortenMoney(TLPU26())
	document.getElementById("timeless29desc").textContent = "Currently: "+shortenMoney(TLPU29())+"x"
    document.getElementById("timeless30desc").textContent = "Currently: "+shortenMoney(TLPU30())+"x"
	
    document.getElementById("dil7desc").textContent = "Currently: "+shortenMoney(player.dilation.dilatedTime.pow(1000).max(1))+"x"
    document.getElementById("dil9desc").textContent = "Currently: exponent ^"+getDilationPower().toFixed(4)+" -> exponent ^"+(getDilationPower()*1.05).toFixed(4)
	if(player.dilation.upgrades.includes(9))document.getElementById("dil9desc").textContent = "Currently: exponent ^"+getDilationPower().toFixed(4)
    document.getElementById("dil10desc").textContent = "Currently: "+shortenMoney(Math.floor(player.dilation.tachyonParticles.div(20000).max(1)))+"/s"
}

function updateDilationUpgradeCosts() {
    document.getElementById("timeless1cost").textContent = "Cost: " + shortenCosts( new Decimal(TIMELESS_UPG_COSTS[1][0]).times(Decimal.pow(TIMELESS_UPG_COSTS[1][1],(player.timeless.rebuyables[1]||0))) ) + " timeless points"
	document.getElementById("timeless2cost").textContent = "Cost: " + shortenCosts( new Decimal(TIMELESS_UPG_COSTS[2][0]).times(Decimal.pow(TIMELESS_UPG_COSTS[2][1],(player.timeless.rebuyables[2]||0))) ) + " timeless points"
	let power=1;
	if(player.timeless.upgrades.includes(33))power=power*0.5;
	if(player.timeless.upgrades.includes(35))power=power*0.5;
	document.getElementById("timeless3cost").textContent = "Cost: " + shortenCosts( new Decimal(TIMELESS_UPG_COSTS[3][0]).times(Decimal.pow(TIMELESS_UPG_COSTS[3][1],(player.timeless.rebuyables[3]||0))).pow(power) ) + " timeless points"
	for(var i=4;i<=TOTAL_TIMELESS_UPGS;i++)document.getElementById("timeless"+i+"cost").textContent = "Cost: " + shortenCosts(TIMELESS_UPG_COSTS[i]) + " timeless points"

	document.getElementById("dil1cost").textContent = "Cost: " + shortenCosts( new Decimal(DIL_UPG_COSTS[1][0]).times(Decimal.pow(DIL_UPG_COSTS[1][1],(player.dilation.rebuyables[1]))) ) + " dilated time"
    document.getElementById("dil2cost").textContent = "Cost: " + shortenCosts( new Decimal(DIL_UPG_COSTS[2][0]).times(Decimal.pow(DIL_UPG_COSTS[2][1],(player.dilation.rebuyables[2]))) ) + " dilated time"
    document.getElementById("dil3cost").textContent = "Cost: " + formatValue(player.options.notation, new Decimal(DIL_UPG_COSTS[3][0]).times(Decimal.pow(DIL_UPG_COSTS[3][1],(player.dilation.rebuyables[3]))), 1, 1) + " dilated time"
    document.getElementById("dil4cost").textContent = "Cost: " + shortenCosts(DIL_UPG_COSTS[4]) + " dilated time"
    document.getElementById("dil5cost").textContent = "Cost: " + shortenCosts(DIL_UPG_COSTS[5]) + " dilated time"
    document.getElementById("dil6cost").textContent = "Cost: " + shortenCosts(DIL_UPG_COSTS[6]) + " dilated time"
    document.getElementById("dil7cost").textContent = "Cost: " + shortenCosts(DIL_UPG_COSTS[7]) + " dilated time"
    document.getElementById("dil8cost").textContent = "Cost: " + shortenCosts(DIL_UPG_COSTS[8]) + " dilated time"
    document.getElementById("dil9cost").textContent = "Cost: " + shortenCosts(DIL_UPG_COSTS[9]) + " dilated time"
    document.getElementById("dil10cost").textContent = "Cost: " + shortenCosts(DIL_UPG_COSTS[10]) + " dilated time"
}






function calcPerSec(amount, pow, hasMult) {
    if (!hasMult) return Decimal.floor(amount).times(pow).times(player.achPow).times(timeMult()).times(player.chall2Pow).dividedBy(player.tickspeed.dividedBy(1000));
    else return Decimal.floor(amount).times(pow).times(player.achPow).times(dimMults()).times(timeMult()).times(player.chall2Pow).dividedBy(player.tickspeed.dividedBy(1000));
}

document.getElementById("quickReset").onclick = function () {
    if (player.resets === 0 || player.currentChallenge === 'challenge5') player.resets--;
    else player.resets -= 2;
    while (player.tickBoughtThisInf.pastResets.length > 0) {
      let entry = player.tickBoughtThisInf.pastResets.pop()
      if (entry.resets <= player.resets) {
        // it has fewer resets than we do, put it back and we're done.
        player.tickBoughtThisInf.pastResets.push(entry);
        break;
      } else {
        // we will have at least this many resets, set our remaining tickspeed upgrades
        // and then throw the entry away
        player.tickBoughtThisInf.current = entry.current;
      }
    }
    softReset(1);
}


function updateInfPower() {
    document.getElementById("infPowAmount").textContent = shortenMoney(player.infinityPower)
	
  let infpow = player.infinityPower;
  
  dilationstart = getDilationStart();
    if(infpow.log10()>=dilationstart){
	  infpow = Decimal.pow(10, Math.pow(infpow.log10()/dilationstart, getDilationPower())*dilationstart)
	  if (player.dilation.active)infpow = Decimal.pow(10, Math.pow(infpow.log10()/dilationstart, getDilationPower())*dilationstart)
    }


    document.getElementById("infPowAmountAfterDilation").textContent = shortenMoney(infpow)
    let y = 7;
  if(player.currentChallenge == "postcngm3_2" || player.challenges.includes("postcngm3_2")){
	  y = Math.max(7, Math.pow(player.galaxies + player.tickspeedBoosts / 5, .8)+1);
  }
    document.getElementById("infDimExponent").innerHTML = (Math.round(y) === y) ? y : y.toFixed(2);
    if (player.currentEternityChall == "eterc9"){
		document.getElementById("infDimMultAmount").textContent = shortenMoney((Decimal.pow(Math.max(player.infinityPower.log2(), 1), 4)).max(1))
		document.getElementById("infPowEffect2").style.display="inline";
		document.getElementById("infPowEffect1").style.display="none";
		document.getElementById("infPowEffect3").textContent="Time";
    }else{
		document.getElementById("infDimMultAmount").textContent = shortenMoney(infpow.pow(y))
		document.getElementById("infPowEffect1").style.display="inline";
		document.getElementById("infPowEffect2").style.display="none";
		document.getElementById("infPowEffect3").textContent="Normal";
	}
    if (player.currentEternityChall == "eterc7") document.getElementById("infPowPerSec").textContent = "You are getting " +shortenDimensions(DimensionProduction(1))+" Seventh Dimensions per second."
    else document.getElementById("infPowPerSec").textContent = "You are getting " +shortenDimensions(DimensionProduction(1))+" Infinity Power per second."
}

function updateTimeShards() {
    if (document.getElementById("timedimensions").style.display == "block" && document.getElementById("dimensions").style.display == "block") {
        document.getElementById("timeShardAmount").textContent = shortenMoney(player.timeShards)
		
		let ts=new Decimal(player.timeShards)
		
		 dilationstart = getDilationStart();
    if(ts.log10()>=dilationstart){
	  ts = Decimal.pow(10, Math.pow(ts.log10()/dilationstart, getDilationPower())*dilationstart)
	  if (player.dilation.active)ts = Decimal.pow(10, Math.pow(ts.log10()/dilationstart, getDilationPower())*dilationstart)
    }
		dilationstart4 = getDilationStart4();
    if(ts.log10()>=dilationstart4){
	  ts = Decimal.pow(10, Math.pow(ts.log10()/dilationstart4, getDilationPower())*dilationstart4)
    }
        document.getElementById("timeShardAmountAfterDilation").textContent = shortenMoney(ts)
        document.getElementById("tickThreshold").textContent = shortenMoney(player.tickThreshold)
		
		let ts1=new Decimal(player.timeShards).add(getTimeDimensionProduction(1));
    if(ts1.log10()>=dilationstart){
	  ts1 = Decimal.pow(10, Math.pow(ts1.log10()/dilationstart, getDilationPower())*dilationstart)
	  if (player.dilation.active)ts1 = Decimal.pow(10, Math.pow(ts1.log10()/dilationstart, getDilationPower())*dilationstart)
    }
		dilationstart4 = getDilationStart4();
    if(ts1.log10()>=dilationstart4){
	  ts1 = Decimal.pow(10, Math.pow(ts1.log10()/dilationstart4, getDilationPower())*dilationstart4)
    }
        if (player.currentEternityChall == "eterc7"){
			document.getElementById("timeShardsPerSec").textContent = "You are getting "+shortenDimensions(getTimeDimensionProduction(1))+" Eighth Infinity Dimensions per second."
			document.getElementById("scTD").innerHTML = "Time dimension multipliers are dilated "+(player.dilation.active?"twice ":"")+" after " + shorten(Decimal.pow(10,getDilationStart()))+". <br>Time dimension multipliers are dilated again after " + shorten(Decimal.pow(10,getDilationStart4()))+"."+
			"<br>Time dimension multipliers are dilated again after " + shorten(Decimal.pow(10,getDilationStart5()))+".";
		}
        else{
			document.getElementById("timeShardsPerSec").textContent = "You are getting "+shortenDimensions(getTimeDimensionProduction(1))+" Timeshards per second ("+shortenDimensions(ts1.sub(ts))+" after dilation).";
			document.getElementById("scTD").innerHTML = "Time dimension multipliers and Timeshards are dilated "+(player.dilation.active?"twice ":"")+" after " + shorten(Decimal.pow(10,getDilationStart()))+". <br>Time dimension multipliers and Timeshards are dilated again after " + shorten(Decimal.pow(10,getDilationStart4()))+"."+
			"<br>Time dimension multipliers are dilated again after " + shorten(Decimal.pow(10,getDilationStart5()))+".";
		}
		
    }
}

function TLPPerSecond(){
    let ret=player.timeless.shards.times(Decimal.pow(2, player.timeless.rebuyables[1]||0));
	if(player.timeless.upgrades.includes(10))ret=ret.times(player.galacticSacrifice.galaxyPoints.add(10).log10());
	if(player.timeless.upgrades.includes(18))ret=ret.times(Math.sqrt(player.eternities+1));
	if(player.achievements.includes("ngm4r2"))ret=ret.times(24);
	dilationstart = getDilationStart();
    if(ret.log10()>=dilationstart){
	  ret = Decimal.pow(10, Math.pow(ret.log10()/dilationstart, getDilationPower())*dilationstart)
	  if (player.dilation.active)ret = Decimal.pow(10, Math.pow(ret.log10()/dilationstart, getDilationPower())*dilationstart)
    }
    return ret;
}

function dilatedTimePerSecond(){
    let ret=player.dilation.tachyonParticles.times(Decimal.pow(2, player.dilation.rebuyables[1]));
	if(player.achievements.includes("r137"))ret=ret.times(player.achPow.pow(0.2));
	dilationstart = getDilationStart();
    if(ret.log10()>=dilationstart){
	  ret = Decimal.pow(10, Math.pow(ret.log10()/dilationstart, getDilationPower())*dilationstart)
	  if (player.dilation.active)ret = Decimal.pow(10, Math.pow(ret.log10()/dilationstart, getDilationPower())*dilationstart)
    }
    return ret;
}

function updateDilation() {
    if (document.getElementById("timeless").style.display == "block" && document.getElementById("eternitystore").style.display == "block") {
        document.getElementById("TLSAmount").textContent = shortenMoney(player.timeless.shards)
        document.getElementById("TLPAmount").textContent = shortenMoney(player.timeless.points)
        document.getElementById("TLPPerSecond").textContent = "+" + shortenMoney(TLPPerSecond()) + "/s"
    }
    if (document.getElementById("dilation").style.display == "block" && document.getElementById("eternitystore").style.display == "block") {
        document.getElementById("tachyonParticleAmount").textContent = shortenMoney(player.dilation.tachyonParticles)
        document.getElementById("dilatedTimeAmount").textContent = shortenMoney(player.dilation.dilatedTime)
        document.getElementById("dilatedTimePerSecond").textContent = "+" + shortenMoney(dilatedTimePerSecond()) + "/s"
        document.getElementById("galaxyThreshold").textContent = shortenMoney(player.dilation.nextThreshold)
        document.getElementById("dilatedGalaxies").textContent = player.dilation.freeGalaxies
    }
}


function getNewInfReq() {
    if (!player.infDimensionsUnlocked[0]) return new Decimal("1e1000")
    else if (!player.infDimensionsUnlocked[1]) return new Decimal("1e1450")
    else if (!player.infDimensionsUnlocked[2]) return new Decimal("1e1900")
    else if (!player.infDimensionsUnlocked[3]) return new Decimal("1e2000")
    else if (!player.infDimensionsUnlocked[4]) return new Decimal("1e5000")
    else if (!player.infDimensionsUnlocked[5]) return new Decimal("1e10000")
    else if (!player.infDimensionsUnlocked[6]) return new Decimal("1e20000")
    else return new Decimal("1e40000")
}


function newDimension() {
    if (player.money.gte(getNewInfReq())) {
        if (!player.infDimensionsUnlocked[0]) player.infDimensionsUnlocked[0] = true
        else if (!player.infDimensionsUnlocked[1]) player.infDimensionsUnlocked[1] = true
        else if (!player.infDimensionsUnlocked[2]) player.infDimensionsUnlocked[2] = true
        else if (!player.infDimensionsUnlocked[3]) {
            player.infDimensionsUnlocked[3] = true
            giveAchievement("NEW DIMENSIONS???")
        }
        else if (!player.infDimensionsUnlocked[4]) player.infDimensionsUnlocked[4] = true
        else if (!player.infDimensionsUnlocked[5]) player.infDimensionsUnlocked[5] = true
        else if (!player.infDimensionsUnlocked[6]) player.infDimensionsUnlocked[6] = true
        else if (!player.infDimensionsUnlocked[7]) {
            player.infDimensionsUnlocked[7] = true
            giveAchievement("0 degrees from infinity")
        }
    }
}
var blink = true
setInterval(function() {
    $.getJSON('version.txt', function(data){
        //data is actual content of version.txt, so
        //do whatever you need with it
        //I'd compare it with last result and if it's different
        //show the message received and nag for attention
        //like this:
        if (data.version > player.version) {
            player.version = data.version
            document.getElementById("update").style.display = "block"
            document.getElementById("updatePopup").innerHTML = data.message
            //or some more resilient method
            //like forced news bar with message running over and over
        }
    })
}, 60000)






var nextAt = [new Decimal("1e650"), new Decimal("1e750"), new Decimal("1e1000"), new Decimal("1e1500"), new Decimal("1e3000"), new Decimal("1e4000"), new Decimal("1e5000"), new Decimal("1e8000"), new Decimal("1e9000"), new Decimal("1e10000")]

var goals = [new Decimal("1e650"), new Decimal("1e650"), new Decimal("1e610"), new Decimal(Number.MAX_VALUE), new Decimal("1e3000"), new Decimal("1e2300"), new Decimal("1e2200"), new Decimal("1e5000"), new Decimal("1e3200"), new Decimal("1e7500")]
setInterval(function() {
    if (getDimensionFinalMultiplier(1).gte(new Decimal("1e308")) &&
        getDimensionFinalMultiplier(2).gte(new Decimal("1e308")) &&
        getDimensionFinalMultiplier(3).gte(new Decimal("1e308")) &&
        getDimensionFinalMultiplier(4).gte(new Decimal("1e308")) &&
        getDimensionFinalMultiplier(5).gte(new Decimal("1e308")) &&
        getDimensionFinalMultiplier(6).gte(new Decimal("1e308")) &&
        getDimensionFinalMultiplier(7).gte(new Decimal("1e308")) &&
        getDimensionFinalMultiplier(8).gte(new Decimal("1e308"))) giveAchievement("Can't hold all these infinities")

    if (getDimensionFinalMultiplier(1).lt(getDimensionFinalMultiplier(2)) &&
        getDimensionFinalMultiplier(2).lt(getDimensionFinalMultiplier(3)) &&
        getDimensionFinalMultiplier(3).lt(getDimensionFinalMultiplier(4)) &&
        getDimensionFinalMultiplier(4).lt(getDimensionFinalMultiplier(5)) &&
        getDimensionFinalMultiplier(5).lt(getDimensionFinalMultiplier(6)) &&
        getDimensionFinalMultiplier(6).lt(getDimensionFinalMultiplier(7)) &&
        getDimensionFinalMultiplier(7).lt(getDimensionFinalMultiplier(8))) giveAchievement("How the antitables have turned")



    if (player.infinitied == 0 && player.infinityPoints.lt(new Decimal(1e50)) && player.eternities <= 0) document.getElementById("infinityPoints2").style.display = "none"
    else document.getElementById("infinityPoints2").style.display = "inline-block"

    if (blink && !player.achievements.includes("r78")) {
        document.getElementById("Blink of an eye").style.display = "none"
        blink = false
    }
    else {
        document.getElementById("Blink of an eye").style.display = "block"
        blink = true
    }
    if (player.challenges.includes("postc4")) {
        let temp = 1
        for (var i=0; i < player.challenges.length; i++) {
            if (player.challenges[i].includes("post")) {
                temp *= 2
                document.getElementById("infchallengesbtn").style.display = "inline-block"
            }
        }
        infDimPow = temp
    } else {
        document.getElementById("infchallengesbtn").style.display = "inline-block"
    }

    if (player.break || Object.keys(player.eternityChalls).length > 0 || player.eternityChallUnlocked !== 0) document.getElementById("challTabButtons").style.display = "table"

    document.getElementById("kongip").textContent = "Double your IP gain from all sources (additive). Forever. Currently: x"+kongIPMult+", next: x"+(kongIPMult==1? 2: kongIPMult+2)
    document.getElementById("kongep").textContent = "Triple your EP gain from all sources (additive). Forever. Currently: x"+kongEPMult+", next: x"+(kongEPMult==1? 3: kongEPMult+3)
    document.getElementById("kongdim").textContent = "Double all your normal dimension multipliers (multiplicative). Forever. Currently: x"+kongDimMult+", next: x"+(kongDimMult*2)
    document.getElementById("kongalldim").textContent = "Double ALL the dimension multipliers (Normal, Infinity, Time) (multiplicative until 32x). Forever. Currently: x"+kongAllDimMult+", next: x"+((kongAllDimMult < 32) ? kongAllDimMult * 2 : kongAllDimMult + 32)
    document.getElementById("eternityPoints2").innerHTML = "You have <span class=\"EPAmount2\">"+shortenDimensions(player.eternityPoints)+"</span> Eternity point"+((player.eternityPoints.eq(1)) ? "." : "s.")+(player.eternities >= 1 ?("<br>Eternity point gain is dilated after "+shorten(Decimal.pow(10,getDilationStart()))+".<br>Multiplier to EP gain pre-dilation based on eternities: "+shorten(EternitiesEPMult().div(3))):"");
        if (player.achievements.includes("r102"))document.getElementById("eternityPoints2").innerHTML += "<br>Multiplier to EP gain post-dilation based on eternities: "+shorten(player.eternities+1)
			
    document.getElementById("eternitybtn").style.display = (player.infinityPoints.gte(player.eternityChallGoal) && player.infDimensionsUnlocked[7]) ? "inline-block" : "none"
if (player.eternities >= 25)document.getElementById("eternitybtn").style.display = (player.infinityPoints.gte(player.eternityChallGoal)) ? "inline-block" : "none"
if(player.timeless.active)document.getElementById("eternitybtn").style.display = "inline-block"


    if (player.eternities !== 0)document.getElementById("eternitystorebtn").style.display = "inline-block"
    if (player.achievements.includes("r127")){
		document.getElementById("interrealitybtn").style.display = "inline-block";
    }else{
		document.getElementById("interrealitybtn").style.display = "none"
	}
	if (player.eternityPoints.gte(Number.MAX_VALUE) && ECTimesCompleted("eterc12")>=1){
		document.getElementById("interrealityresetbtn").style.display = "inline-block";
    }else{
		document.getElementById("interrealityresetbtn").style.display = "none"
		
	}
    for (var i=1; i <= 10; i++) {
        document.getElementById("postc"+i+"goal").textContent = "Goal: "+shortenCosts(goals[i-1])
    }

    // additional infinity challenges
    document.getElementById("postcngm3_1goal").textContent = "Goal: "+shortenCosts(new Decimal("1e590"))
    document.getElementById("postcngm3_2goal").textContent = "Goal: "+shortenCosts(new Decimal("1e500"))
    document.getElementById("postcngm3_3goal").textContent = "Goal: "+shortenCosts(new Decimal("1e1500"))
    document.getElementById("postcngm3_4goal").textContent = "Goal: "+shortenCosts(new Decimal("1e7500"))
    document.getElementById("postcngm4r_1goal").textContent = "Goal: "+shortenCosts(new Decimal("1e1200"))
    document.getElementById("postcngm4r_2goal").textContent = "Goal: "+shortenCosts(new Decimal("1e1000"))
    document.getElementById("postcngm4r_3goal").textContent = "Goal: "+shortenCosts(new Decimal("1e19500"))
    document.getElementById("postcngm4r_4goal").textContent = "Goal: "+shortenCosts(new Decimal("1e30000"))

    if (player.replicanti.galaxybuyer !== undefined) document.getElementById("replicantiresettoggle").style.display = "inline-block"
    else document.getElementById("replicantiresettoggle").style.display = "none"

    if (player.eternities > 0) document.getElementById("infmultbuyer").style.display = "inline-block"
    else document.getElementById("infmultbuyer").style.display = "none"
    if (player.eternities > 4) document.getElementById("togglecrunchmode").style.display = "inline-block"
    else document.getElementById("togglecrunchmode").style.display = "none"
    if (player.eternities > 8) document.getElementById("galaxybulk").style.display = "inline-block"
    else document.getElementById("galaxybulk").style.display = "none"

    document.getElementById("replicantichance").className = (player.infinityPoints.gte(player.replicanti.chanceCost) && (player.replicanti.chance < 1 || player.achievements.includes("ngm4r4"))) ? "storebtn" : "unavailablebtn"
    document.getElementById("replicantiinterval").className = (player.infinityPoints.gte(player.replicanti.intervalCost) && ((player.replicanti.interval !== 50) || player.timestudy.studies.includes(22)) && (player.replicanti.interval !== 1)) ? "storebtn" : "unavailablebtn"
    document.getElementById("replicantimax").className = (player.infinityPoints.gte(player.replicanti.galCost)) ? "storebtn" : "unavailablebtn"
    document.getElementById("replicantireset").className = (player.replicanti.galaxies < player.replicanti.gal && player.replicanti.amount.gte(Number.MAX_VALUE)) ? "storebtn" : "unavailablebtn"
    document.getElementById("replicantiunlock").className = (player.infinityPoints.gte(1e80)) ? "storebtn" : "unavailablebtn"
    updateTheoremButtons()

    if (getTickSpeedMultiplier() < 0.01) giveAchievement("Do you even bend time bro?")

    if (player.achievements.includes("r28")) document.getElementById("bulklabel").textContent = "Buy max dimboosts every X seconds:"
    else document.getElementById("bulklabel").textContent = "Bulk DimBoost Amount:"

    if (player.eternities > 10) {
        for (var i=1;i<player.eternities-9 && i < 9; i++) {
            document.getElementById("infauto"+i).style.visibility = "visible"
        }
        document.getElementById("toggleallinfdims").style.visibility = "visible"
    } else {
        for (var i=1; i<9; i++) {
            document.getElementById("infauto"+i).style.visibility = "hidden"
        }
        document.getElementById("toggleallinfdims").style.visibility = "hidden"
    }

    if (player.eternities !== 0) document.getElementById("eternityconf").style.display = "inline-block"
    else document.getElementById("eternityconf").style.display = "none"
    if (player.eternities >= 40) document.getElementById("replauto1").style.visibility = "visible"
    else document.getElementById("replauto1").style.visibility = "hidden"
    if (player.eternities >= 60) document.getElementById("replauto2").style.visibility = "visible"
    else document.getElementById("replauto2").style.visibility = "hidden"
    if (player.eternities >= 80) document.getElementById("replauto3").style.visibility = "visible"
    else document.getElementById("replauto3").style.visibility = "hidden"
    if (player.eternities >= 100) document.getElementById("autoBuyerEter").style.display = "inline-block"

    if (player.eternities == 0) document.getElementById("pasteternities").style.display = "none"
    else document.getElementById("pasteternities").style.display = "inline-block"
    if (player.challenges.length > 1) document.getElementById("challengetimesbtn").style.display = "inline-block"
    else document.getElementById("challengetimesbtn").style.display = "none"
    if (player.infinitied > 0  || player.eternities > 0) document.getElementById("pastinfs").style.display = "inline-block"
    else document.getElementById("pastinfs").style.display = "none"

    if (player.infinitied !== 0 || player.eternities !== 0) document.getElementById("bigCrunchAnimBtn").style.display = "inline-block"
    else document.getElementById("bigCrunchAnimBtn").style.display = "none"
    if (!player.dilation.tachyonParticles.eq(0)) document.getElementById("tachyonParticleAnimBtn").style.display = "inline-block"
    else document.getElementById("tachyonParticleAnimBtn").style.display = "none"

    if (player.eternities > 10 && player.currentEternityChall !== "eterc8") {
        for (var i=1;i<player.eternities-9 && i < 9; i++) {
            if (player.infDimBuyers[i-1]) {
                buyMaxInfDims(i)
                buyManyInfinityDimension(i)
            }
        }
    }

    if (player.eternities >= 40 && player.replicanti.auto[0] && player.currentEternityChall !== "eterc8") {
        while (player.infinityPoints.gte(player.replicanti.chanceCost) && player.currentEternityChall !== "eterc8" && (player.replicanti.chance < 1 || player.achievements.includes("ngm4r4"))) upgradeReplicantiChance()
    }

    if (player.eternities >= 60 && player.replicanti.auto[1] && player.currentEternityChall !== "eterc8") {
        while (player.infinityPoints.gte(player.replicanti.intervalCost) && player.currentEternityChall !== "eterc8" && ((player.timestudy.studies.includes(22)) ? player.replicanti.interval > 1 : player.replicanti.interval > 50)) upgradeReplicantiInterval()
    }

    if (player.eternities >= 80 && player.replicanti.auto[2] && player.currentEternityChall !== "eterc8") {
        while (upgradeReplicantiGalaxy()) continue
    }

	for(var i=1;i<=12;i++){
		document.getElementById("eterc"+i+"goal").textContent = "Goal: "+shortenCosts(getECGoal("eterc"+i)) + " IP"
		document.getElementById("eterc"+i+"completed").textContent = "Completed "+ECTimesCompleted("eterc"+i)+" times."
	}
	updateECUnlockButtons()




    if (player.currentEternityChall == "eterc8") {
        document.getElementById("eterc8repl").style.display = "block"
        document.getElementById("eterc8ids").style.display = "block"
        document.getElementById("eterc8repl").textContent = "You have "+player.eterc8repl+" purchases left."
        document.getElementById("eterc8ids").textContent = "You have "+player.eterc8ids+" purchases left."
    } else {
        document.getElementById("eterc8repl").style.display = "none"
        document.getElementById("eterc8ids").style.display = "none"
    }

    if (player.currentEternityChall == "eterc12" && player.thisEternity >= Math.max(2 * (5 - ECTimesCompleted("eterc12")), 1)) {
        document.getElementById("challfail").style.display = "block"
        setTimeout(exitChallenge, 500)
        giveAchievement("You're a mistake")
        failureCount++
        if (failureCount > 9) giveAchievement("You're a failure")
    }

    document.getElementById("infinitiedBank").style.display = (player.infinitiedBank > 0) ? "block" : "none"
    document.getElementById("infinitiedBank").textContent = "You have " + Math.floor(player.infinitiedBank).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",") + " banked infinities."

    if (infchallengeTimes < 7.5) giveAchievement("Never again")
    if (player.infinityPoints.gte(new Decimal("1e22000")) && player.timestudy.studies.length == 0) giveAchievement("What do I have to do to get rid of you")
    if (player.replicanti.galaxies >= 180*player.galaxies && player.galaxies > 0) giveAchievement("Popular music")
    if (player.eternityPoints.gte(Number.MAX_VALUE)) giveAchievement("But I wanted another prestige layer...")
    if (player.infinityPoints.gte(1e100) && player.firstAmount.equals(0) && player.infinitied == 0 && player.resets <= 4 && player.galaxies <= 1 && player.replicanti.galaxies == 0) giveAchievement("Like feasting on a behind")
    if (player.infinityPoints.gte('9.99999e999')) giveAchievement("This achievement doesn't exist II");
    if (player.infinityPoints.gte('1e30008')) giveAchievement("Can you get infinite IP?");
    if (player.infinitied > 2e6) giveAchievement("2 Million Infinities")
    if (player.postC3Reward.gte("9.9999e9999")) giveAchievement("This achievement doesn't exist")
    if (player.timeless.shards.gte('86400')) giveAchievement("A day lost...");
    if (player.money.gte("1e9500")) giveAchievement("I got a few to spare")
    if (player.infinityPower.gt(1)) giveAchievement("A new beginning.");
    if (player.infinityPower.gt(1e6)) giveAchievement("1 million is a lot"); //TBD
    if (player.infinityPower.gt(1e260)) giveAchievement("Minute of infinity"); //TBD
    if (player.totalTickGained >= 308) giveAchievement("Infinite time");
    if (player.firstPow >= 10e30) giveAchievement("I forgot to nerf that")
    if (player.money >= 10e79) giveAchievement("Antimatter Apocalypse")
    if (player.totalTimePlayed >= 10 * 60 * 60 * 24 * 8) giveAchievement("One for each dimension")
    if (player.seventhAmount > 1e12) giveAchievement("Multidimensional");
    if (player.tickspeed.lt(1e-26)) giveAchievement("Faster than a potato");
    if (player.tickspeed.lt(1e-55)) giveAchievement("Faster than a squared potato");
    if (Math.random() < 0.00001) giveAchievement("Do you feel lucky? Well do ya punk?")
    if ((player.matter.gte(2.586e15) && player.currentChallenge == "postc8") || player.matter.gte(Number.MAX_VALUE)) giveAchievement("It's not called matter dimensions is it?")

    document.getElementById("timelessTabbtn").style.display = (player.eternityUpgrades.includes(7)) ? "inline-block" : "none"
    document.getElementById("dilationTabbtn").style.display = (player.dilation.studies.includes(1)) ? "inline-block" : "none"
    updateDilationUpgradeButtons()

    if (player.infinityDimension1.baseAmount == 0 &&
        player.infinityDimension2.baseAmount == 0 &&
        player.infinityDimension3.baseAmount == 0 &&
        player.infinityDimension4.baseAmount == 0 &&
        player.infinityDimension5.baseAmount == 0 &&
        player.infinityDimension6.baseAmount == 0 &&
        player.infinityDimension7.baseAmount == 0 &&
        player.infinityDimension8.baseAmount == 0 &&
        player.infMultCost.equals(10) &&
        player.infinityPoints.gt(new Decimal("1e140000"))) {
        giveAchievement("I never liked this infinity stuff anyway")
    }

    if (player.replicanti.amount.gt(new Decimal("1e20000"))) giveAchievement("When will it be enough?")
    if (player.tickspeed.e < -8296262) giveAchievement("Faster than a potato^286078")
    if (player.timestudy.studies.length == 0 && player.dilation.active && player.infinityPoints.e >= 20000) giveAchievement("This is what I have to do to get rid of you.")
    if (player.why >= 1e6) giveAchievement("Should we tell them about buy max...")

}, 1000)

function fact(v) {
    let ret=1;
    do {ret *= v} while (--v > 1)
    return ret;
}

var postC5Count = 0;
var IPminpeak = new Decimal(0)
var EPminpeak = new Decimal(0)
var replicantiTicks = 0


function gameLoop(diff) {
    var thisUpdate = new Date().getTime();
    if (thisUpdate - player.lastUpdate >= 21600000) giveAchievement("Don't you dare to sleep")
    if (typeof diff === 'undefined') var diff = Math.min(thisUpdate - player.lastUpdate, 21600000);
    diff = diff / 100;
    if (diff < 0) diff = 1;
    if (player.currentEternityChall === "eterc12") diff = diff / 1000;
    diff = diff * diffMultiplier
    if (player.thisInfinityTime < -10) player.thisInfinityTime = Infinity
    if (player.bestInfinityTime < -10) player.bestInfinityTime = Infinity
    if (diff > player.autoTime && !player.break) player.infinityPoints = player.infinityPoints.plus(player.autoIP.times(diff/player.autoTime))
    player.matter = player.matter.times(Decimal.pow((1.03 + player.resets/200 + player.galaxies/100), diff));
    if (player.currentChallenge == "postc4" || player.currentChallenge == "postc8")player.matter = player.matter.times(Decimal.pow((1.03 + player.resets/200 + player.galaxies/100), diff*25));
    if (player.matter.gt(player.money) && (player.currentChallenge == "challenge12" || player.currentChallenge == "postc4")) {
        if (player.resets > 0) player.resets--;
        softReset(0);
    }

    if (player.currentChallenge == "postc10") postc10Mult = postc10Mult.times(Math.pow(0.000000046416, diff))

    if (player.currentChallenge == "challenge3" || player.matter.gte(1)) player.chall3Pow = player.chall3Pow.times(Decimal.pow(1.00038, diff));
    player.chall2Pow = Math.min(player.chall2Pow + diff/1800, 1);
    if (player.currentChallenge == "postc5") {
        postC5Count++;
        if (postC5Count >= 8 || diff > 80) {
            sacrifice();
            postC5Count = 0;
        }
    }
    if (player.infinityUpgrades.includes("passiveGen")) player.partInfinityPoint += diff / player.bestInfinityTime;
    if (player.partInfinityPoint >= 100) {
        player.infinityPoints = player.infinityPoints.plus(getIPMult().times(player.partInfinityPoint/10));
        player.partInfinityPoint = 0;
    }

    if (player.partInfinityPoint >= 10) {
        player.partInfinityPoint -= 10;
        player.infinityPoints = player.infinityPoints.plus(getIPMult());
    }



    if (player.infinityUpgrades.includes("infinitiedGeneration") && player.currentEternityChall !== "eterc4") player.partInfinitied += diff / player.bestInfinityTime;
    
        let infGain = 1;
        if (player.thisInfinityTime > 50 && player.achievements.includes("r87")) infGain = 250;
        if (player.timestudy.studies.includes(32)) infGain *= Math.max(player.resets,1);
	if(player.timestudy.studies.includes(43) && player.currentEternityChall !== "eterc4")player.partInfinitied = player.partInfinitied + diff * infGain/1000
if(player.timestudy.studies.includes(53))player.infinitiedBank += diff * infGain/1000*timeStudy53()

	if (player.partInfinitied >= 50) {
        player.infinitied += Math.floor(player.partInfinitied/5)
        player.partInfinitied = player.partInfinitied - Math.floor(player.partInfinitied/5);
    }

    if (player.partInfinitied >= 5) {
        player.partInfinitied -= 5;
        player.infinitied ++;
    }
	
    player.infinityPoints = player.infinityPoints.plus(bestRunIppm.times(player.offlineProd/100).times(diff/600))

    if (player.money.lte(Number.MAX_VALUE) || (player.break && player.currentChallenge == "") || (player.currentChallenge != "" && player.money.lte(player.challengeTarget))) {

        if (player.currentChallenge != "challenge7" &&  player.currentChallenge != "postcngm3_3"&&  player.currentChallenge != "postcngm4r_1"&& player.currentEternityChall != "eterc3") {
            for (let tier = 7; tier >= 1; --tier) {
                var name = TIER_NAMES[tier];

                player[name + 'Amount'] = player[name + 'Amount'].plus(getDimensionProductionPerSecond(tier + 1).times(diff / 100));
            }
        } else if (player.currentEternityChall != "eterc3") {
            for (let tier = 6; tier >= 1; --tier) {
                var name = TIER_NAMES[tier];

                player[name + 'Amount'] = player[name + 'Amount'].plus(getDimensionProductionPerSecond(tier + 2).times(diff / 100));
            }
        } else {
            for (let tier = 3; tier >= 1; --tier) {
                var name = TIER_NAMES[tier];

                player[name + 'Amount'] = player[name + 'Amount'].plus(getDimensionProductionPerSecond(tier + 1).times(diff / 100));
            }
        }

        if (player.currentChallenge == "challenge3" || player.currentChallenge == "postc4") {
            player.money = player.money.plus(getDimensionProductionPerSecond(1).times(diff/10).times(player.chall3Pow));
            player.totalmoney = player.totalmoney.plus(getDimensionProductionPerSecond(1).times(diff/10).times(player.chall3Pow));
        } else {
            player.money = player.money.plus(getDimensionProductionPerSecond(1).times(diff/10));
            player.totalmoney = player.totalmoney.plus(getDimensionProductionPerSecond(1).times(diff/10));
        }
        if (player.currentChallenge == "challenge7" || player.currentChallenge == "postcngm3_3") {
            player.money = player.money.plus(getDimensionProductionPerSecond(2).times(diff/10));
            player.totalmoney = player.totalmoney.plus(getDimensionProductionPerSecond(2).times(diff/10))
        }
    }

    document.getElementById("dimTabButtons").style.display = "inline-block"

    if (player.currentEternityChall === "eterc12") player.totalTimePlayed += diff*1000
    else player.totalTimePlayed += diff
    player.thisInfinityTime += diff
    player.thisEternity += diff

    document.getElementById("tdtabbtn").style.display = "inline-block"

    for (let tier=1;tier<9;tier++) {
        if (tier != 8 && (player.infDimensionsUnlocked[tier-1] || ECTimesCompleted("eterc7") > 0)) player["infinityDimension"+tier].amount = player["infinityDimension"+tier].amount.plus(DimensionProduction(tier+1).times(diff/100))
        if (player.infDimensionsUnlocked[tier-1]) {
            document.getElementById("infRow"+tier).style.display = "inline-block"
            document.getElementById("dimTabButtons").style.display = "inline-block"
            var idtabshown = true;
        } else {
            document.getElementById("infRow"+tier).style.display = "none"
            document.getElementById("idtabbtn").style.display = "none"
        }
        if (idtabshown === true || player.eternities >= 1) {
            document.getElementById("idtabbtn").style.display = "inline-block"
        }

       if(player.currentChallenge == "postcngm4r_1" && tier<7) player["timeDimension"+tier].amount = player["timeDimension"+tier].amount.plus(getTimeDimensionProduction(tier+2).times(diff/100))
        else if (tier <8) player["timeDimension"+tier].amount = player["timeDimension"+tier].amount.plus(getTimeDimensionProduction(tier+1).times(diff/100))
    }

    if (player.infinitied > 0 && player.eternities < 1) {
        document.getElementById("dimTabButtons").style.display = "inline-block"
        document.getElementById("dtabbtn").style.display = "inline-block"
        document.getElementById("prodtabbtn").style.display = "inline-block"
    }
    if (player.eternities > 0) document.getElementById("dimTabButtons").style.display = "inline-block"

    if (player.currentEternityChall !== "eterc7") player.infinityPower = player.infinityPower.plus(DimensionProduction(1).times(diff/10))
    else if (player.currentChallenge !== "challenge4" && player.currentChallenge !== "postc4") player.seventhAmount = player.seventhAmount.plus(DimensionProduction(1).times(diff/10))




    if (player.currentEternityChall == "eterc7") player.infinityDimension8.amount = player.infinityDimension8.amount.plus(getTimeDimensionProduction(1).times(diff/10))
    else player.timeShards = player.timeShards.plus(getTimeDimensionProduction(1).times(diff/10))

    if (getTimeDimensionProduction(1).gt(0) && ECTimesCompleted("eterc7") > 0) player.infinityDimension8.amount = player.infinityDimension8.amount.plus(getTimeDimensionProduction(1).pow(ECTimesCompleted("eterc7")*0.2).minus(1).times(diff/10))

    let gain;
    if (player.timeShards.gt(0)) {
        let tsMult = 1.15;
        if (player.timestudy.studies.includes(171)) tsMult = 1.13;
		let ts=new Decimal(player.timeShards)
		
		 dilationstart = getDilationStart();
    if(ts.log10()>=dilationstart){
	  ts = Decimal.pow(10, Math.pow(ts.log10()/dilationstart, getDilationPower())*dilationstart)
	  if (player.dilation.active)ts = Decimal.pow(10, Math.pow(ts.log10()/dilationstart, getDilationPower())*dilationstart)
    }
		dilationstart4 = getDilationStart4();
    if(ts.log10()>=dilationstart4){
	  ts = Decimal.pow(10, Math.pow(ts.log10()/dilationstart4, getDilationPower())*dilationstart4)
    }
		let temp=player.totalTickGained - Math.pow(player.tickspeedBoosts,0.9)*100;
		if(player.challenges.includes("postcngm3_3"))temp = player.totalTickGained - Math.pow(player.tickspeedBoosts,0.9)*100*Math.max(Math.sqrt(player.galacticSacrifice.galaxyPoints.max(1).log10()) / 3,1)
        if(temp>0)player.tickThreshold = new Decimal(1).times(tsMult).pow(temp)
		else new Decimal(1).div(tsMult).pow(-temp)
		gain = Math.ceil(Math.max(new Decimal(ts).dividedBy(player.tickThreshold).log10() / Math.log10(tsMult),0))
		if(gain<0)gain=0;
        player.totalTickGained += gain
        player.tickspeed = player.tickspeed.times(Decimal.pow(getTickSpeedMultiplier(), gain))
        player.postC3Reward = player.postC3Reward.times(Decimal.pow(getPostC3RewardMult(), gain))
        temp=player.totalTickGained - Math.pow(player.tickspeedBoosts,0.9)*100;
		if(player.challenges.includes("postcngm3_3"))temp = player.totalTickGained - Math.pow(player.tickspeedBoosts,0.9)*100*Math.max(Math.sqrt(player.galacticSacrifice.galaxyPoints.max(1).log10()) / 3,1)
        if(temp>0)player.tickThreshold = new Decimal(1).times(tsMult).pow(temp)
		else new Decimal(1).div(tsMult).pow(-temp)
	    document.getElementById("totaltickgained").textContent = "You've gained "+player.totalTickGained.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",")+" tickspeed upgrades."
		if (player.achievements.includes("r105"))document.getElementById("totaltickgained").textContent += " 'Infinite Time' multiplier: "+shorten(player.postC3Reward.pow(infiniteTimeStrength()))+".";
        if (player.tickspeedBoosts)document.getElementById("totaltickgained").textContent += " Tickspeed Boosts are reducing timeshard requirement by "+shorten(Math.pow(player.tickspeedBoosts,0.9)*100*Math.max(Math.sqrt(player.galacticSacrifice.galaxyPoints.max(1).log10()) / 3,1))+" tickspeed upgrades";
        updateTickSpeed();
    }

    if (!player.achievements.includes("r51")) {
        document.getElementById("eternityPoints2").style.display = "none"
        document.getElementById("eternitystorebtn").style.display = "none"
    }
    else {
        document.getElementById("eternityPoints2").style.display = "inline-block"
        document.getElementById("eternitystorebtn").style.display = "inline-block"
    }

    if (player.money.gte(Number.MAX_VALUE) && (!player.break || (player.currentChallenge != "" && player.money.gte(player.challengeTarget)))) {
        document.getElementById("bigcrunch").style.display = 'inline-block';
        if ((player.currentChallenge == "" || player.options.retryChallenge) && (player.bestInfinityTime <= 600 || player.break)) {}
        else showTab('emptiness');
    } else document.getElementById("bigcrunch").style.display = 'none';

    if (player.break && player.money.gte(Number.MAX_VALUE) && player.currentChallenge == "") {
        document.getElementById("postInfinityButton").style.display = "inline-block"
    } else {
        document.getElementById("postInfinityButton").style.display = "none"
    }


    if (player.break) document.getElementById("iplimit").style.display = "inline"
    else document.getElementById("iplimit").style.display = "none"

    var currentIPmin = gainedInfinityPoints().dividedBy(player.thisInfinityTime/600)
    if (currentIPmin.gt(IPminpeak)) IPminpeak = currentIPmin
    if (IPminpeak.lte("1e100000")) document.getElementById("postInfinityButton").innerHTML = "<b>Big Crunch for "+shortenDimensions(gainedInfinityPoints())+" Infinity Points.</b><br>"+shortenDimensions(currentIPmin) + " IP/min"+"<br>Peaked at "+shortenDimensions(IPminpeak)+" IP/min"
    else document.getElementById("postInfinityButton").innerHTML = "<b>Big Crunch for "+shortenDimensions(gainedInfinityPoints())+" Infinity Points.</b>"

    if (nextAt[player.postChallUnlocked] === undefined) document.getElementById("nextchall").textContent = " "
    else if (!player.achievements.includes("r133")) {
        document.getElementById("nextchall").textContent = "Next challenge unlocks at "+ shortenCosts(nextAt[player.postChallUnlocked]) + " antimatter."
        while (player.money.gte(nextAt[player.postChallUnlocked]) && player.challenges.includes("postc10") === false && player.postChallUnlocked != 10) {
            if (player.postChallUnlocked != 10) player.postChallUnlocked += 1
            if (player.eternities > 6) player.challenges.push("postc"+player.postChallUnlocked)
            updateChallenges()
        }
    }
    let interval = player.replicanti.interval
  if (player.galacticSacrifice.upgrades.includes(51))interval=interval/galUpgrade51();
    if (player.timestudy.studies.includes(133) || player.replicanti.amount.gt(Number.MAX_VALUE)) interval *= 10
    if (player.timestudy.studies.includes(192) && player.timestudy.studies.includes(62)) interval /= 3
    if (player.replicanti.amount.gt(Number.MAX_VALUE) && !player.achievements.includes("r134")) interval *= 4
    if (player.timestudy.studies.includes(213)) interval /= 20
    if (player.achievements.includes("r134")) interval /= 2
    if (player.replicanti.amount.gt(Number.MAX_VALUE)) interval = Math.max(interval * Math.pow(1.2, (player.replicanti.amount.log10() - 308)/308), interval)
    var est = Math.log(getReplicantiReplicateAmount()) * 1000 / interval

    var current = player.replicanti.amount.ln()

    if (player.replicanti.unl && player.currentChallenge !== "postcngm4r_3"/* && (diff > 5 || interval < 50 || player.timestudy.studies.includes(192))*/) {
        var gained = Decimal.pow(Math.E, current +(diff*est/10))
        if (player.timeless.upgrades.includes(26)||player.achievements.includes("ngm4r4")||player.timestudy.studies.includes(192)) gained = Decimal.pow(Math.E, current +Math.log((diff*est/10) * (Math.log10(1.2)/308)+1) / (Math.log10(1.2)/308))
        let maxReplicantiExponent = 1024;
	    if (player.timeless.upgrades.includes(26))maxReplicantiExponent *= TLPU26();
	    if (player.achievements.includes("ngm4r4"))maxReplicantiExponent *= Math.pow(1+player.replicanti.chance,0.15);
		if (player.timestudy.studies.includes(62))maxReplicantiExponent *= 1.5;
	    player.replicanti.amount = Decimal.min(Decimal.pow(2, maxReplicantiExponent), gained)
        if (player.timestudy.studies.includes(192)) player.replicanti.amount = gained
        replicantiTicks = 0
    }/* else {
        if (interval <= replicantiTicks && player.replicanti.unl) {
            if (player.replicanti.amount.lte(100)) {
                var temp = player.replicanti.amount
                for (var i=0; temp.gt(i); i++) {
                    if (player.replicanti.chance > Math.random()) player.replicanti.amount = player.replicanti.amount.plus(1)
                }
            } else {
                var temp = Decimal.round(player.replicanti.amount.dividedBy(100))
                if (Math.round(player.replicanti.chance) !== 1) {
                    let counter = 0
                    for (var i=0; i<100; i++) {
                        if (player.replicanti.chance > Math.random()) {
                            counter++;
                        }
                    }
                    player.replicanti.amount = Decimal.min(Number.MAX_VALUE, temp.times(counter).plus(player.replicanti.amount))
                    if (player.timestudy.studies.includes(192)) player.replicanti.amount = temp.times(counter).plus(player.replicanti.amount)
                    counter = 0
                } else {
                    if (player.timestudy.studies.includes(192)) player.replicanti.amount = player.replicanti.amount.times(2)
                    else player.replicanti.amount = Decimal.min(Number.MAX_VALUE, player.replicanti.amount.times(2))

                }
            }
            replicantiTicks -= interval
        }

    }*/
    if (player.replicanti.amount !== 0) replicantiTicks += player.options.updateRate


    if (current == Decimal.ln(Number.MAX_VALUE) && player.thisInfinityTime < 600*30) giveAchievement("Is this safe?");
    if (player.replicanti.galaxies >= 10 && player.thisInfinityTime < 150) giveAchievement("The swarm");

    if (player.replicanti.galaxybuyer && player.replicanti.amount.gte(Number.MAX_VALUE) && !player.timestudy.studies.includes(131)) {
        document.getElementById("replicantireset").click()
    }
    if (player.timestudy.studies.includes(22) ? player.replicanti.interval !== 1 : (player.replicanti.interval !== 50)) document.getElementById("replicantiinterval").innerHTML = "Interval: "+(interval).toFixed(3)+"ms<br>-> "+Math.max(interval*0.9).toFixed(3)+" Costs: "+shortenCosts(player.replicanti.intervalCost)+" IP"
    else document.getElementById("replicantiinterval").textContent = "Interval: "+(interval).toFixed(3)+"ms"


    if (player.infMultBuyer) {
        var dif = player.infinityPoints.e - player.infMultCost.e +1
        if (dif > 0) {
            player.infMult = player.infMult.times(Decimal.pow(getIPMultMultiplier(), dif))
            player.infMultCost = player.infMultCost.times(Decimal.pow(10, dif))
            document.getElementById("infiMult").innerHTML = "Multiply infinity points from all sources by " + getIPMult().toFixed(3) + "<br>currently: "+shorten(getIPMult()) +"x<br>Cost: "+shortenCosts(player.infMultCost)+" IP"
            player.infinityPoints = player.infinityPoints.minus(player.infMultCost.dividedBy(10))
            if (player.autobuyers[11].priority !== undefined && player.autobuyers[11].priority !== null && player.autoCrunchMode == "amount") player.autobuyers[11].priority = player.autobuyers[11].priority.times(Decimal.pow(2, dif));
            if (player.autoCrunchMode == "amount") document.getElementById("priority12").value = player.autobuyers[11].priority
        }
    }


    var estimate = Math.max((Math.log(Number.MAX_VALUE) - current) / est, 0)
    document.getElementById("replicantiapprox").textContent ="Approximately "+ timeDisplay(estimate*10) + " Until Infinite Replicanti"

    document.getElementById("replicantiamount").textContent = shortenDimensions(player.replicanti.amount)
    document.getElementById("replicantimult").textContent = shorten(getReplMult())

    var currentEPmin = gainedEternityPoints().dividedBy(player.thisEternity/600)
    if (currentEPmin.gt(EPminpeak) && player.infinityPoints.gte(Number.MAX_VALUE)) EPminpeak = currentEPmin
    document.getElementById("eternitybtn").innerHTML = "Eternity for <b>"+shortenDimensions(gainedEternityPoints())+"</b> Eternity points.<br>("+shortenDimensions(gainedEternityPointsBeforeDilation())+" before dilation)<br>"+shortenDimensions(currentEPmin)+ " EP/min"
    if (gainedEternityPoints().gte("1e1000"))document.getElementById("eternitybtn").innerHTML = "Eternity for <b>"+shortenDimensions(gainedEternityPoints())+"</b> Eternity points.<br>("+shortenDimensions(gainedEternityPointsBeforeDilation())+" before dilation)"
    if (player.dilation.active){
            if (Math.pow(Decimal.log10(player.money) / 400, 1.5) * (Math.pow(3, player.dilation.rebuyables[3])) - player.dilation.totalTachyonParticles <= 0) {
                document.getElementById("eternitybtn").innerHTML = "Eternity for <b>"+shortenDimensions(gainedEternityPoints())+"</b> Eternity points.<br>Reach <b>" + shortenMoney(Decimal.pow(10, Math.pow(player.dilation.tachyonParticles * Math.pow(400, 1.5) / Math.pow(3, player.dilation.rebuyables[3]), 2/3))) + "</b> antimatter to gain more Tachyon Particles."
            } else {
                document.getElementById("eternitybtn").innerHTML = "Eternity for <b>"+shortenDimensions(gainedEternityPoints())+"</b> Eternity points and <b>"+shortenMoney(Math.round(Math.max(Math.pow(Decimal.log10(player.money) / 400, 1.5) * (Math.pow(3, player.dilation.rebuyables[3])) - player.dilation.totalTachyonParticles, 0) * 10)/10) +"</b> Tachyon Particles."
            }
    }
    if (player.timeless.active){
            document.getElementById("eternitybtn").innerHTML = "Exit Timeless for <b>"+shortenDimensions(gainedTimelessShards())+"</b> Timeless Shards.<br>Next Timeless Shard at "+shortenDimensions(nextTimelessShardAt())+" Timeshards.";
			if (player.timeless.upgrades.includes(32))document.getElementById("eternitybtn").innerHTML = "Exit Timeless.";
            
    }
    if (player.currentEternityChall !== "") document.getElementById("eternitybtn").textContent = "Other challenges await.. I need to become Eternal"
    updateMoney();
    updateCoinPerSec();
    updateDimensions()
    updateChallenges()
    updateInfCosts()
    updateInfinityDimensions();
    updateInfPower();
    updateTimeDimensions()
    updateTimeShards()
    updateDilation()
    if (getDimensionProductionPerSecond(1).gt(player.money) && !player.achievements.includes("r44")) {
        Marathon+=player.options.updateRate/1000;
        if (Marathon >= 30) giveAchievement("Over in 30 seconds");
    } else {
        Marathon = 0;
    }
    if (DimensionProduction(1).gt(player.infinityPower) && player.currentEternityChall != "eterc7" && !player.achievements.includes("r113")) {
        Marathon2+=player.options.updateRate/1000;
        if (Marathon2 >= 60) giveAchievement("Long lasting relationship");
    } else {
        Marathon2 = 0;
    }
    if (player.eternities >= 1 && (player.options.notation == "Standard" || player.options.notation == "Emojis" || player.options.notation == "Brackets")) {
        painTimer += player.options.updateRate/1000;
        if (painTimer >= 600) giveAchievement("Do you enjoy pain?");
    }

    if(player.money.gt(Math.pow(10,63))) giveAchievement("Supersanic");

    for (let tier = 1; tier <= 8; ++tier) {
        var name = TIER_NAMES[tier];
        if (player.currentChallenge != "challenge10" && player.currentChallenge != "postc4") {
            document.getElementById(name).className = canAfford(player[name + 'Cost']) ? 'storebtn' : 'unavailablebtn';
            document.getElementById(name + 'Max').className = canAfford(player[name + 'Cost'].times(10 - dimBought(tier))) ? 'storebtn' : 'unavailablebtn';
        } else {
            if (tier >= 3) {
                document.getElementById(name).className = player[TIER_NAMES[tier-2] + 'Amount'].gte(player[name + 'Cost']) ? 'storebtn' : 'unavailablebtn';
                document.getElementById(name + 'Max').className = player[TIER_NAMES[tier-2] + 'Amount'].gte(player[name + 'Cost'].times(10 - dimBought(tier))) ? 'storebtn' : 'unavailablebtn';
            } else {
                document.getElementById(name).className = canAfford(player[name + 'Cost']) ? 'storebtn' : 'unavailablebtn';
                document.getElementById(name + 'Max').className = canAfford(player[name + 'Cost'].times(10 - dimBought(tier))) ? 'storebtn' : 'unavailablebtn';
            }
        }
    }
    if (player.firstAmount.lt(1)) document.getElementById("first").className = 'storebtn';

    for (var tier = 1; tier < 9; tier++) {
        var dim = player["infinityDimension"+tier]
      	dim.cost = new Decimal(infBaseCost[tier]).times(Decimal.pow(infCostMults[tier]/getInfBuy10CostDiv(tier), (dim.baseAmount/10)*(ECTimesCompleted("eterc12")?1-ECTimesCompleted("eterc12")*0.008:1)))
        if (player.infinityPoints.gte(dim.cost)) document.getElementById("infMax"+tier).className = "storebtn"
        else document.getElementById("infMax"+tier).className = "unavailablebtn"
    }

    for (var tier = 1; tier < 9; tier++) {
        if (player.eternityPoints.gte(player["timeDimension"+tier].cost)) document.getElementById("timeMax"+tier).className = "storebtn"
        else document.getElementById("timeMax"+tier).className = "unavailablebtn"
		if(!player.achievements.includes("r63") || tier > Math.min(player.eternities,3) + 1)document.getElementById("timeMax"+tier).style.display="none";else document.getElementById("timeMax"+tier).style.display="";
        if (player.money.gte(player["timeDimension"+tier].costAntimatter)) document.getElementById("timeMax"+tier+"Antimatter").className = "storebtn"
        else document.getElementById("timeMax"+tier+"Antimatter").className = "unavailablebtn"
		if(player.timeless.active)document.getElementById("timeMax"+tier+"Antimatter").style.display="none";else document.getElementById("timeMax"+tier+"Antimatter").style.display="";
    }

	if (player.eternityUpgrades.includes(7))player.timeless.points = player.timeless.points.plus(TLPPerSecond().mul(diff/10))
	
    if (player.dilation.studies.includes(1)) player.dilation.dilatedTime = player.dilation.dilatedTime.plus(dilatedTimePerSecond().mul(diff/10))
    if (player.dilation.studies.includes(2))document.getElementById("timeMax5").style.display="";
    if (player.dilation.studies.includes(3))document.getElementById("timeMax6").style.display="";
    if (player.dilation.studies.includes(4))document.getElementById("timeMax7").style.display="";
    if (player.dilation.studies.includes(5))document.getElementById("timeMax8").style.display="";
	
    if (player.dilation.nextThreshold.lte(player.dilation.dilatedTime)) {
        let thresholdMult = 1.35 + 3.65 * Math.pow(0.8, player.dilation.rebuyables[2])
        // for (var i = 0; i < player.dilation.rebuyables[2]; i++) {
        //     thresholdMult *= Math.min( 1 - (Math.pow(0.8, i) / 10), 0.999)
        // }
        player.dilation.nextThreshold = player.dilation.nextThreshold.times(thresholdMult)
        player.dilation.freeGalaxies += 1
        if (player.dilation.upgrades.includes(4)) player.dilation.freeGalaxies += 1
    }




    if (player.money.gte(player.tickSpeedCost) && canBuyTickSpeed()) {
        document.getElementById("tickSpeed").className = 'storebtn';
        document.getElementById("tickSpeedMax").className = 'storebtn';
    } else {
        document.getElementById("tickSpeed").className = 'unavailablebtn';
        document.getElementById("tickSpeedMax").className = 'unavailablebtn';
    }

    if (player.infinityPoints.gt(0) || player.eternities !== 0) {
        document.getElementById("infinitybtn").style.display = "block";
        document.getElementById("infi11").className = "infinistorebtn1"
        document.getElementById("infi21").className = "infinistorebtn2"
        if (player.infinityUpgrades.includes("timeMult")) document.getElementById("infi12").className = "infinistorebtn1"
        else document.getElementById("infi12").className = "infinistorebtnlocked"
        if (player.infinityUpgrades.includes("dimMult")) document.getElementById("infi22").className = "infinistorebtn2"
        else document.getElementById("infi22").className = "infinistorebtnlocked"
        if (player.infinityUpgrades.includes("18Mult")) document.getElementById("infi13").className = "infinistorebtn1"
        else document.getElementById("infi13").className = "infinistorebtnlocked"
        if (player.infinityUpgrades.includes("27Mult")) document.getElementById("infi23").className = "infinistorebtn2"
        else document.getElementById("infi23").className = "infinistorebtnlocked"
        if (player.infinityUpgrades.includes("36Mult")) document.getElementById("infi14").className = "infinistorebtn1"
        else document.getElementById("infi14").className = "infinistorebtnlocked"
        if (player.infinityUpgrades.includes("45Mult") && player.infinityPoints.gte(2)) document.getElementById("infi24").className = "infinistorebtn2"
        else document.getElementById("infi24").className = "infinistorebtnlocked"
        if (player.infinityPoints.gte(3)) document.getElementById("infi31").className = "infinistorebtn3"
        else document.getElementById("infi31").className = "infinistorebtnlocked"
        if (player.infinityUpgrades.includes("timeMult2") && player.infinityPoints.gte(5)) document.getElementById("infi32").className = "infinistorebtn3"
        else document.getElementById("infi32").className = "infinistorebtnlocked"
        if (player.infinityUpgrades.includes("unspentBonus") && player.infinityPoints.gte(7)) document.getElementById("infi33").className = "infinistorebtn3"
        else document.getElementById("infi33").className = "infinistorebtnlocked"
        if (player.infinityUpgrades.includes("resetMult") && player.infinityPoints.gte(10)) document.getElementById("infi34").className = "infinistorebtn3"
        else document.getElementById("infi34").className = "infinistorebtnlocked"
        if (player.infinityPoints.gte(20)) document.getElementById("infi41").className = "infinistorebtn4"
        else document.getElementById("infi41").className = "infinistorebtnlocked"
        if (player.infinityUpgrades.includes("skipReset1") && player.infinityPoints.gte(40)) document.getElementById("infi42").className = "infinistorebtn4"
        else document.getElementById("infi42").className = "infinistorebtnlocked"
        if (player.infinityUpgrades.includes("skipReset2") && player.infinityPoints.gte(80)) document.getElementById("infi43").className = "infinistorebtn4"
        else document.getElementById("infi43").className = "infinistorebtnlocked"
        if (player.infinityUpgrades.includes("skipReset3") && player.infinityPoints.gte(500)) document.getElementById("infi44").className = "infinistorebtn4"
        else document.getElementById("infi44").className = "infinistorebtnlocked"
        if (player.infinityUpgrades.includes("skipResetGalaxy") && player.infinityUpgrades.includes("passiveGen") && player.infinityUpgrades.includes("galaxyBoost") && player.infinityUpgrades.includes("resetBoost") && player.infinityPoints.gte(player.infMultCost)) {
            document.getElementById("infiMult").className = "infinimultbtn"
        } else document.getElementById("infiMult").className = "infinistorebtnlocked"

        if (player.infinityPoints.gte(1e3)) document.getElementById("postinfi01").className = "infinistorebtn1"
        else document.getElementById("postinfi01").className = "infinistorebtnlocked"

        if (player.infinityPoints.gte(2e4)) document.getElementById("postinfi02").className = "infinistorebtn1"
        else document.getElementById("postinfi02").className = "infinistorebtnlocked"

        if (player.infinityPoints.gte(5e5)) document.getElementById("postinfi03").className = "infinistorebtn1"
        else document.getElementById("postinfi03").className = "infinistorebtnlocked"

        if (player.infinityPoints.gte(player.dimPowerIncreaseCost)) document.getElementById("postinfi04").className = "infinimultbtn"
        else document.getElementById("postinfi04").className = "infinistorebtnlocked"

        if (player.infinityPoints.gte(1e4)) document.getElementById("postinfi11").className = "infinistorebtn1"
        else document.getElementById("postinfi11").className = "infinistorebtnlocked"

        if (player.infinityPoints.gte(5e4)) document.getElementById("postinfi21").className = "infinistorebtn1"
        else document.getElementById("postinfi21").className = "infinistorebtnlocked"

        if (player.infinityPoints.gte(player.tickSpeedMultDecreaseCost)) document.getElementById("postinfi31").className = "infinimultbtn"
        else document.getElementById("postinfi31").className = "infinistorebtnlocked"

        if (player.infinityPoints.gte(5e11)) document.getElementById("postinfi41").className = "infinistorebtn1"
        else document.getElementById("postinfi41").className = "infinistorebtnlocked"

        if (player.infinityPoints.gte(1e5)) document.getElementById("postinfi12").className = "infinistorebtn1"
        else document.getElementById("postinfi12").className = "infinistorebtnlocked"

        if (player.infinityPoints.gte(1e6)) document.getElementById("postinfi22").className = "infinistorebtn1"
        else document.getElementById("postinfi22").className = "infinistorebtnlocked"

        if (player.infinityPoints.gte(1e7)) document.getElementById("postinfi32").className = "infinistorebtn1"
        else document.getElementById("postinfi32").className = "infinistorebtnlocked"

        if (player.infinityPoints.gte(player.dimensionMultDecreaseCost)) document.getElementById("postinfi42").className = "infinimultbtn"
        else document.getElementById("postinfi42").className = "infinistorebtnlocked"

        if (player.infinityPoints.gte(20e6)) document.getElementById("postinfi13").className = "infinistorebtn1"
        else document.getElementById("postinfi13").className = "infinistorebtnlocked"

        if (player.infinityPoints.gte(5e6)) document.getElementById("postinfi23").className = "infinistorebtn1"
        else document.getElementById("postinfi23").className = "infinistorebtnlocked"

        if (player.infinityPoints.gte(1e15)) document.getElementById("postinfi33").className = "infinistorebtn1"
        else document.getElementById("postinfi33").className = "infinistorebtnlocked"

        if (player.infinityPoints.gte(1e22)) document.getElementById("postinfi50").className = "infinistorebtn1"
        else document.getElementById("postinfi50").className = "infinistorebtnlocked"

        if (player.infinityPoints.gte(1e26)) document.getElementById("postinfi51").className = "infinistorebtn1"
        else document.getElementById("postinfi51").className = "infinistorebtnlocked"

        if (player.infinityPoints.gte(1e22)) document.getElementById("postinfi52").className = "infinistorebtn1"
        else document.getElementById("postinfi52").className = "infinistorebtnlocked"

        if (player.infinityPoints.gte(1e32)) document.getElementById("postinfi53").className = "infinistorebtn1"
        else document.getElementById("postinfi53").className = "infinistorebtnlocked"

        if (player.infinityPoints.gte(1e50)) document.getElementById("postinfi60").className = "infinistorebtn1"
        else document.getElementById("postinfi60").className = "infinistorebtnlocked"

	if (player.infinityPoints.gte(1e69)) document.getElementById("postinfi61").className = "infinistorebtn1"
        else document.getElementById("postinfi61").className = "infinistorebtnlocked"

	if (player.infinityPoints.gte(1e170)) document.getElementById("postinfi62").className = "infinistorebtn1"
        else document.getElementById("postinfi62").className = "infinistorebtnlocked"

	if (player.infinityPoints.gte(1e80)) document.getElementById("postinfi63").className = "infinistorebtn1"
        else document.getElementById("postinfi63").className = "infinistorebtnlocked"

        if (player.infinityPoints.gte(1e160)) document.getElementById("postinfi70").className = "infinistorebtn1"
        else document.getElementById("postinfi70").className = "infinistorebtnlocked"

	if (player.infinityPoints.gte(1e180)) document.getElementById("postinfi71").className = "infinistorebtn1"
        else document.getElementById("postinfi71").className = "infinistorebtnlocked"

	if (player.infinityPoints.gte(1e200)) document.getElementById("postinfi72").className = "infinistorebtn1"
        else document.getElementById("postinfi72").className = "infinistorebtnlocked"

	if (player.infinityPoints.gte(1e215)) document.getElementById("postinfi73").className = "infinistorebtn1"
        else document.getElementById("postinfi73").className = "infinistorebtnlocked"

        if (player.infinityPoints.gte(player.offlineProdCost)) document.getElementById("offlineProd").className = "infinimultbtn"
        else document.getElementById("offlineProd").className = "infinistorebtnlocked"

    }
    if (player.infinityPoints.equals(0)){
        document.getElementById("infi11").className = "infinistorebtnlocked"
        document.getElementById("infi12").className = "infinistorebtnlocked"
        document.getElementById("infi13").className = "infinistorebtnlocked"
        document.getElementById("infi14").className = "infinistorebtnlocked"
        document.getElementById("infi21").className = "infinistorebtnlocked"
        document.getElementById("infi22").className = "infinistorebtnlocked"
        document.getElementById("infi23").className = "infinistorebtnlocked"
        document.getElementById("infi24").className = "infinistorebtnlocked"
        document.getElementById("infi31").className = "infinistorebtnlocked"
        document.getElementById("infi32").className = "infinistorebtnlocked"
        document.getElementById("infi33").className = "infinistorebtnlocked"
        document.getElementById("infi34").className = "infinistorebtnlocked"
        document.getElementById("infi41").className = "infinistorebtnlocked"
        document.getElementById("infi42").className = "infinistorebtnlocked"
        document.getElementById("infi43").className = "infinistorebtnlocked"
        document.getElementById("infi44").className = "infinistorebtnlocked"
        document.getElementById("infiMult").className = "infinistorebtnlocked"
    }

    galacticUpgradeButtonTypeDisplay();

    if (player.autobuyers[11]%1 === 0 || player.autobuyers[11].interval>100) document.getElementById("break").className = "infinistorebtnlocked"
    else document.getElementById("break").className = "infinistorebtn2"


    if (player.resets > 4) {
        document.getElementById("confirmation").style.display = "inline-block";
        document.getElementById("sacrifice").style.display = "inline-block";
    } else {
        document.getElementById("confirmation").style.display = "none";
        document.getElementById("sacrifice").style.display = "none";
    }
	document.getElementById("sacrificebtn").style.display = "none"
	document.getElementById("quantumBlock").style.display = "none"
	document.getElementById("galaxyPoints2").className = (player.break || player.eternities > 0)? "QK" : "EP";
	if (player.galaxies + player.replicanti.galaxies + player.dilation.freeGalaxies > 0) {
    document.getElementById("gConfirmation").style.display = "inline-block";
		document.getElementById("gSacrifice").style.display = "inline-block"
		document.getElementById("gSacrifice").innerHTML = "Galactic Sacrifice (" + formatValue(player.options.notation, getGSAmount(), 2, 0) + " GP)"
		if (getGSAmount().gt(0)){
			document.getElementById("gSacrifice").className = "storebtn"
			document.getElementById("sacrificebtn").style.display = ""
			document.getElementById("sacpos").className = (player.break || player.eternities > 0) ? "quantumpos" : "eterpos";
			document.getElementById("sacrificebtn").innerHTML = "<b>Galactic Sacrifice for " + shortenDimensions(getGSAmount()) + " Galaxy points.</b>"
		}
		else document.getElementById("gSacrifice").className = "unavailablebtn"
		document.getElementById("gSacrifice").setAttribute('ach-tooltip', "Gain " + formatValue(player.options.notation, getGSAmount(), 2, 0) + " GP")
	} else {
    document.getElementById("gConfirmation").style.display = "none";
		document.getElementById("gSacrifice").style.display = "none"
	}
	if ((player.break || player.eternities > 0))document.getElementById("quantumBlock").style.display = ""
	
    if (player.infinitied > 0) document.getElementById("sacrifice").style.display = "inline-block";

    if (player.eightAmount > 0 && player.resets > 4 && player.currentEternityChall !== "eterc3") document.getElementById("sacrifice").className = "storebtn"
    else document.getElementById("sacrifice").className = "unavailablebtn"

    if (player.autobuyers[11]%1 !== 0 && player.autobuyers[11].interval == 100) {
        document.getElementById("postinftable").style.display = "inline-block"
        document.getElementById("breaktable").style.display = "inline-block"
    } else {
        document.getElementById("postinftable").style.display = "none"
        document.getElementById("breaktable").style.display = "none"
    }

    if (player.autobuyers[11].interval == 100) document.getElementById("abletobreak").style.display = "none"


    document.getElementById("infinitybtn").style.display = "none";
    document.getElementById("challengesbtn").style.display = "none";

    if (player.money.gte(Number.MAX_VALUE) && (((player.currentChallenge != "" && player.money.gte(player.challengeTarget)) && !player.options.retryChallenge) || (player.bestInfinityTime > 600 && !player.break))) {
        document.getElementById("dimensionsbtn").style.display = "none";
        document.getElementById("optionsbtn").style.display = "none";
        document.getElementById("statisticsbtn").style.display = "none";
        document.getElementById("achievementsbtn").style.display = "none";
        document.getElementById("challengesbtn").style.display = "none";
        document.getElementById("galaxybtn").style.display = "none";
        document.getElementById("infinitybtn").style.display = "none";
        document.getElementById("tickSpeed").style.visibility = "hidden";
        document.getElementById("tickSpeedMax").style.visibility = "hidden";
        document.getElementById("tickLabel").style.visibility = "hidden";
        document.getElementById("tickSpeedAmount").style.visibility = "hidden";
        document.getElementById("tickSpeedPurchases").style.visibility = "hidden";
    } else {
        document.getElementById("dimensionsbtn").style.display = "inline-block";
        document.getElementById("optionsbtn").style.display = "inline-block";
        document.getElementById("statisticsbtn").style.display = "inline-block";
        document.getElementById("achievementsbtn").style.display = "inline-block";
        if (player.infinitied > 0) {
            document.getElementById("infinitybtn").style.display = "inline-block";
            document.getElementById("challengesbtn").style.display = "inline-block";
        }
    }

    document.getElementById("epmult").className = player.eternityPoints.gte(player.epmultCost) ? "eternityupbtn" : "eternityupbtnlocked"

    if (player.infinityUpgrades.includes("bulkBoost")) document.getElementById("bulkdimboost").style.display = "inline"
    else document.getElementById("bulkdimboost").style.display = "none"

    if (player.infinityUpgrades.includes("timeMult")) document.getElementById("infi11").className = "infinistorebtnbought"
    if (player.infinityUpgrades.includes("dimMult")) document.getElementById("infi21").className = "infinistorebtnbought"
    if (player.infinityUpgrades.includes("18Mult")) document.getElementById("infi12").className = "infinistorebtnbought"
    if (player.infinityUpgrades.includes("27Mult")) document.getElementById("infi22").className = "infinistorebtnbought"
    if (player.infinityUpgrades.includes("36Mult")) document.getElementById("infi13").className = "infinistorebtnbought"
    if (player.infinityUpgrades.includes("45Mult")) document.getElementById("infi23").className = "infinistorebtnbought"
    if (player.infinityUpgrades.includes("resetBoost")) document.getElementById("infi14").className = "infinistorebtnbought"
    if (player.infinityUpgrades.includes("galaxyBoost")) document.getElementById("infi24").className = "infinistorebtnbought"
    if (player.infinityUpgrades.includes("timeMult2")) document.getElementById("infi31").className = "infinistorebtnbought"
    if (player.infinityUpgrades.includes("unspentBonus")) document.getElementById("infi32").className = "infinistorebtnbought"
    if (player.infinityUpgrades.includes("resetMult")) document.getElementById("infi33").className = "infinistorebtnbought"
    if (player.infinityUpgrades.includes("passiveGen")) document.getElementById("infi34").className = "infinistorebtnbought"
    if (player.infinityUpgrades.includes("skipReset1")) document.getElementById("infi41").className = "infinistorebtnbought"
    if (player.infinityUpgrades.includes("skipReset2")) document.getElementById("infi42").className = "infinistorebtnbought"
    if (player.infinityUpgrades.includes("skipReset3")) document.getElementById("infi43").className = "infinistorebtnbought"
    if (player.infinityUpgrades.includes("skipResetGalaxy")) document.getElementById("infi44").className = "infinistorebtnbought"

    if (player.infinityUpgrades.includes("galPointMult")) document.getElementById("postinfi01").className = "infinistorebtnbought"
    if (player.infinityUpgrades.includes("dimboostCost")) document.getElementById("postinfi02").className = "infinistorebtnbought"
    if (player.infinityUpgrades.includes("galCost")) document.getElementById("postinfi03").className = "infinistorebtnbought"
    if (player.extraDimPowerIncrease >= 50) document.getElementById("postinfi04").className = "infinistorebtnbought"
    if (player.infinityUpgrades.includes("totalMult")) document.getElementById("postinfi11").className = "infinistorebtnbought"
    if (player.infinityUpgrades.includes("currentMult")) document.getElementById("postinfi21").className = "infinistorebtnbought"
    if (player.tickSpeedMultDecrease <= 2) document.getElementById("postinfi31").className = "infinistorebtnbought"
    if (player.infinityUpgrades.includes("achievementMult")) document.getElementById("postinfi22").className = "infinistorebtnbought"
    if (player.infinityUpgrades.includes("infinitiedMult")) document.getElementById("postinfi12").className = "infinistorebtnbought"
    if (player.infinityUpgrades.includes("postGalaxy")) document.getElementById("postinfi41").className = "infinistorebtnbought"
    if (player.infinityUpgrades.includes("challengeMult")) document.getElementById("postinfi32").className = "infinistorebtnbought"
    if (player.infinityUpgrades.includes("postinfi50")) document.getElementById("postinfi50").className = "infinistorebtnbought"
    if (player.infinityUpgrades.includes("postinfi51")) document.getElementById("postinfi51").className = "infinistorebtnbought"
    if (player.infinityUpgrades.includes("postinfi52")) document.getElementById("postinfi52").className = "infinistorebtnbought"
    if (player.infinityUpgrades.includes("postinfi53")) document.getElementById("postinfi53").className = "infinistorebtnbought"
    if (player.infinityUpgrades.includes("postinfi60")) document.getElementById("postinfi60").className = "infinistorebtnbought"
    if (player.infinityUpgrades.includes("postinfi61")) document.getElementById("postinfi61").className = "infinistorebtnbought"
    if (player.infinityUpgrades.includes("postinfi62")) document.getElementById("postinfi62").className = "infinistorebtnbought"
    if (player.infinityUpgrades.includes("postinfi63")) document.getElementById("postinfi63").className = "infinistorebtnbought"
    if (player.infinityUpgrades.includes("postinfi70")) document.getElementById("postinfi70").className = "infinistorebtnbought"
    if (player.infinityUpgrades.includes("postinfi71")) document.getElementById("postinfi71").className = "infinistorebtnbought"
    if (player.infinityUpgrades.includes("postinfi72")) document.getElementById("postinfi72").className = "infinistorebtnbought"
    if (player.infinityUpgrades.includes("postinfi73")) document.getElementById("postinfi73").className = "infinistorebtnbought"

    if (player.dimensionMultDecrease <= 3) document.getElementById("postinfi42").className = "infinistorebtnbought"
    if (player.offlineProd == 50) document.getElementById("offlineProd").className = "infinistorebtnbought"


    if (player.infinityUpgrades.includes("infinitiedGeneration")) document.getElementById("postinfi13").className = "infinistorebtnbought"
    if (player.infinityUpgrades.includes("bulkBoost")) document.getElementById("postinfi23").className = "infinistorebtnbought"
    if (player.infinityUpgrades.includes("autoBuyerUpgrade")) document.getElementById("postinfi33").className = "infinistorebtnbought"

    if (player.currentChallenge !== "") {
        document.getElementById("progressbar").style.width = Decimal.min((Decimal.log10(player.money.plus(1)) / Decimal.log10(player.challengeTarget) * 100), 100).toFixed(2) + "%"
        document.getElementById("progresspercent").textContent = Decimal.min((Decimal.log10(player.money.plus(1)) / Decimal.log10(player.challengeTarget) * 100), 100).toFixed(2) + "%"
        document.getElementById("progresspercent").setAttribute('ach-tooltip',"Percentage to challenge goal")
    } else if (!player.break) {
        document.getElementById("progressbar").style.width = Decimal.min((Decimal.log10(player.money.plus(1)) / Decimal.log10(Number.MAX_VALUE) * 100), 100).toFixed(2) + "%"
        document.getElementById("progresspercent").textContent = Decimal.min((Decimal.log10(player.money.plus(1)) / Decimal.log10(Number.MAX_VALUE) * 100), 100).toFixed(2) + "%"
        document.getElementById("progresspercent").setAttribute('ach-tooltip',"Percentage to Infinity")
    } else if (player.infDimensionsUnlocked.includes(false)) {
        document.getElementById("progressbar").style.width = Decimal.min(player.money.e / getNewInfReq().e * 100, 100).toFixed(2) + "%"
        document.getElementById("progresspercent").textContent = Decimal.min(player.money.e / getNewInfReq().e * 100, 100).toFixed(2) + "%"
        document.getElementById("progresspercent").setAttribute('ach-tooltip',"Percentage to next dimension unlock")
    } else {
        document.getElementById("progressbar").style.width = Decimal.min(Decimal.log10(player.infinityPoints.plus(1)) / Decimal.log10(Number.MAX_VALUE)  * 100, 100).toFixed(2) + "%"
        document.getElementById("progresspercent").textContent = Decimal.min(Decimal.log10(player.infinityPoints.plus(1)) / Decimal.log10(Number.MAX_VALUE)  * 100, 100).toFixed(2) + "%"
        document.getElementById("progresspercent").setAttribute('ach-tooltip',"Percentage to Eternity")
    }

    if (player.eternities > 0) {
        document.getElementById("infinitybtn").style.display = "inline-block";
        document.getElementById("challengesbtn").style.display = "inline-block";
    }

    document.getElementById("ec1reward").textContent = "Reward: "+shortenMoney(EC1Reward())+"x post-dilation multiplier on all Time Dimensions (based on time spent this Eternity, nerfed in Timeless)"
    document.getElementById("ec2reward").textContent = "Reward: Infinity power affects 1st Infinity Dimension with reduced effect, Currently: "+shortenMoney(EC2Reward())+"x"
    document.getElementById("ec3reward").textContent = "Reward: Increase the multiplier for buying 10 dimensions, Currently: "+getDimensionPowerMultiplier().toFixed(2)+"x"
    document.getElementById("ec4reward").textContent = "Reward: Infinity Dimension multiplier from unspent IP, Currently: "+shortenMoney(EC4Reward())+"x"
    document.getElementById("ec5reward").textContent = "Reward: Distant, Further, Remote and Dark Matter Galaxy cost scaling starts "+((ECTimesCompleted("eterc5")*2))+" galaxies later."
    document.getElementById("ec6reward").textContent = "Reward: Further reduce the dimension cost multiplier increase, Currently: "+player.dimensionMultDecrease.toFixed(1)+"x "
    document.getElementById("ec7reward").textContent = "Reward: First Time dimension produces Eighth Infinity Dimensions, Currently: "+shortenMoney(getTimeDimensionProduction(1).pow(ECTimesCompleted("eterc7")*0.2).minus(1).max(0))+" per second. "
    document.getElementById("ec8reward").textContent = "Reward: Infinity power powers up replicanti galaxies, Currently: " + (Math.max(Math.pow(Math.log10(player.infinityPower.plus(1).log10()+1), 0.05 * ECTimesCompleted("eterc8"))-1, 0) * 100).toFixed(2) + "%"
    document.getElementById("ec9reward").textContent = "Reward: Infinity Dimension post-dilation multiplier based on time shards, Currently: "+shortenMoney(EC9Reward())+"x "
    document.getElementById("ec10reward").textContent = "Reward: Time dimensions post-dilation multiplier from infinitied stat, Currently: "+shortenMoney(EC10Reward())+"x "
    document.getElementById("ec11reward").textContent = "Reward: Further reduce the tickspeed cost multiplier increase, Currently: "+player.tickSpeedMultDecrease.toFixed(2)+"x "
    document.getElementById("ec12reward").textContent = "Reward: Infinity Dimension cost multipliers are reduced. (x^"+(1-ECTimesCompleted("eterc12")*0.008)+")"

    // let extraGals = 0
    // if (player.timestudy.studies.includes(225)) extraGals += Math.floor(player.replicanti.amount.e / 2500)
    // if (player.timestudy.studies.includes(226)) extraGals += Math.floor(player.replicanti.gal / 40)
    // if (extraGals !== 0) document.getElementById("replicantireset").innerHTML = "Reset replicanti amount, but get a free galaxy<br>"+player.replicanti.galaxies + "+"+extraGals+ " replicated galaxies created."
    // else document.getElementById("replicantireset").innerHTML = "Reset replicanti amount, but get a free galaxy<br>"+player.replicanti.galaxies + " replicated galaxies created."

    document.getElementById("ec10span").textContent = shortenMoney(ec10bonus) + "x"
    var scale1 = [2.82e-45,1e-42,7.23e-30,5e-21,9e-17,6.2e-11,5e-8,3.555e-6,7.5e-4,1,2.5e3,2.6006e6,3.3e8,5e12,4.5e17,1.08e21,1.53e24,1.41e27,5e32,8e36,1.7e45,1.7e48,3.3e55,3.3e61,5e68,1e73,3.4e80,1e113,Number.MAX_VALUE,new Decimal("1e65000")];
    var scale2 = [" protons."," nucleui."," Hydrogen atoms."," viruses."," red blood cells."," grains of sand."," grains of rice."," teaspoons."," wine bottles."," fridge-freezers."," Olympic-sized swimming pools."," Great Pyramids of Giza."," Great Walls of China."," large asteroids.",
                " dwarf planets."," Earths."," Jupiters."," Suns."," red giants."," hypergiant stars."," nebulas."," Oort clouds."," Local Bubbles."," galaxies."," Local Groups."," Sculptor Voids."," observable universes."," Dimensions.", " Infinity Dimensions.", " Time Dimensions."];
    var id = 0;
    if (player.money.times(4.22419e-105).gt(2.82e-45)) {
        if (player.money.times(4.22419e-105).gt(scale1[scale1.length - 1])) id = scale1.length - 1;
        else {
            while (player.money.times(4.22419e-105).gt(scale1[id])) id++;
            if (id > 0) id--;
        }
        if (id >= 7 && id < 11) document.getElementById("infoScale").textContent = "If every antimatter were a planck volume, you would have enough to fill " + formatValue(player.options.notation, player.money * 4.22419e-105 / scale1[id], 2, 1) + scale2[id];
        else document.getElementById("infoScale").textContent = "If every antimatter were a planck volume, you would have enough to make " + formatValue(player.options.notation, player.money.times(4.22419e-105).dividedBy(scale1[id]), 2, 1) + scale2[id];
    } else { //does this part work correctly? i doubt it does
        if (player.money.times(1e-54) < 2.82e-45) document.getElementById("infoScale").textContent = "If every antimatter were " + formatValue(player.options.notation,2.82e-45 / 1e-54 / player.money, 2, 1) + " attometers cubed, you would have enough to make a proton."
        else if (player.money * 1e-63 < 2.82e-45) document.getElementById("infoScale").textContent = "If every antimatter were " + formatValue(player.options.notation,2.82e-45 / 1e-63 / player.money, 2, 1) + " zeptometers cubed, you would have enough to make a proton."
        else if (player.money * 1e-72 < 2.82e-45) document.getElementById("infoScale").textContent = "If every antimatter were " + formatValue(player.options.notation,2.82e-45 / 1e-72 / player.money, 2, 1) + " yoctometers cubed, you would have enough to make a proton."
        else document.getElementById("infoScale").textContent = "If every antimatter were " + formatValue(player.options.notation,2.82e-45 / 4.22419e-105 / player.money, 2, 1) + " planck volumes, you would have enough to make a proton."
    }
    if (player.money.gt(new Decimal("1e100000"))) {
        document.getElementById("infoScale").innerHTML = "<br>If you wrote 3 numbers a second, it would take you <br>" + timeDisplay(player.money.log10()*10/3) + "<br> to write down your antimatter amount.";
    }

    var shiftRequirement = getShiftRequirement(0);

    if (player[TIER_NAMES[shiftRequirement.tier] + 'Amount'] >= shiftRequirement.amount) {
        document.getElementById("softReset").className = 'storebtn';
    } else {
        document.getElementById("softReset").className = 'unavailablebtn';
    }

    if (player.eightAmount >= getGalaxyRequirement()) {
        document.getElementById("secondSoftReset").className = 'storebtn';
    } else {
        document.getElementById("secondSoftReset").className = 'unavailablebtn';
    }

    if (player.currentChallenge == "challenge4" && player.sixthAmount >= getGalaxyRequirement()) {
        document.getElementById("secondSoftReset").className = 'storebtn';
    }

    if (player.currentChallenge == "challenge2" || player.currentChallenge == "postc4") document.getElementById("chall2Pow").style.display = "inline-block"
    else document.getElementById("chall2Pow").style.display = "none"
    if (player.currentChallenge == "challenge3" || player.currentChallenge == "postc4") document.getElementById("chall3Pow").style.display = "inline-block"
    else document.getElementById("chall3Pow").style.display = "none"

    document.getElementById("chall2Pow").textContent = (player.chall2Pow*100).toFixed(2) + "%"
    document.getElementById("chall3Pow").textContent = shorten(player.chall3Pow*100) + "%"


    if (player.infDimensionsUnlocked[7] == false && player.break && player.eternities <= 24) {
        document.getElementById("newDimensionButton").style.display = "inline-block"
    } else document.getElementById("newDimensionButton").style.display = "none"

    if (player.money.gte(getNewInfReq())) document.getElementById("newDimensionButton").className = "newdim"
    else document.getElementById("newDimensionButton").className = "newdimlocked"

    var infdimpurchasewhileloop = 1;
    while (player.eternities > 24 && getNewInfReq().lt(player.money) && player.infDimensionsUnlocked[7] === false) {
        for (i=0; i<8; i++) {
            if (player.infDimensionsUnlocked[i]) infdimpurchasewhileloop++
        }
        newDimension()
        if (player.infDimBuyers[i-1]) buyMaxInfDims(infdimpurchasewhileloop)
        infdimpurchasewhileloop = 1;
    }

    document.getElementById("newDimensionButton").textContent = "Get " + shortenCosts(getNewInfReq()) + " antimatter to unlock a new Dimension."

    document.getElementById("sacrifice").setAttribute('ach-tooltip', "Boosts 8th Dimension by " + formatValue(player.options.notation, calcSacrificeBoost(), 2, 2) + "x");

    document.getElementById("sacrifice").textContent = "Dimensional Sacrifice ("+formatValue(player.options.notation, calcSacrificeBoost(), 2, 2)+"x)"
    if (isNaN(player.totalmoney)) player.totalmoney = new Decimal(10)
    if (player.timestudy.studies.includes(181)) player.infinityPoints = player.infinityPoints.plus(gainedInfinityPoints().times(diff/1000))
    if (player.timestudy.studies.includes(181)) player.galacticSacrifice.galaxyPoints = player.galacticSacrifice.galaxyPoints.plus(getGSAmount().times(diff/1000))
    if (player.dilation.upgrades.includes(10)) {
        player.timestudy.theorem += parseFloat(player.dilation.tachyonParticles.div(20000).times(diff/10).toString())
        if (document.getElementById("timestudies").style.display != "none" && document.getElementById("eternitystore").style.display != "none") {
            if (player.timestudy.theorem>99999) document.getElementById("timetheorems").innerHTML = "You have <span style='display:inline' class=\"TheoremAmount\">"+shortenMoney(player.timestudy.theorem)+"</span> Time "+"Theorems."
            else document.getElementById("timetheorems").innerHTML = "You have <span style='display:inline' class=\"TheoremAmount\">"+player.timestudy.theorem.toFixed(0)+"</span> Time "+ (player.timestudy.theorem == 1 ? "Theorem." : "Theorems.")
            updateTimeStudyButtons()
        }
    }

    document.getElementById("infinityPoints1").innerHTML = "You have <span class=\"IPAmount1\">"+shortenDimensions(player.infinityPoints)+"</span> Infinity points."
    document.getElementById("infinityPoints2").innerHTML = "You have <span class=\"IPAmount2\">"+shortenDimensions(player.infinityPoints)+"</span> Infinity points."

    player.lastUpdate = thisUpdate;
}

function simulateTime(seconds, real) {
window.offlineTimeout=0;

    //the game is simulated at a 50ms update rate, with a max of 1000 ticks
    //warning: do not call this function with real unless you know what you're doing
    document.getElementById("offlineprogress").style.display = "block"
    var ticks = seconds * 20;
    var bonusDiff = 0;
    var playerStart = Object.assign({}, player);
    if (ticks > 1000 && !real) {
        bonusDiff = (ticks - 1000) / 20;
        ticks = 1000;
    }
    let ticksDone = 0
    for (ticksDone=0; ticksDone<ticks; ticksDone++) {
        gameLoop(50+bonusDiff)
        autoBuyerTick();
        if (real) console.log(ticksDone)
    }
    var popupString = "While you were away"
    if (player.money.gt(playerStart.money)) popupString+= ",<br> your antimatter increased "+shortenMoney(player.money.log10() - (playerStart.money).log10())+" orders of magnitude"
    if (player.infinityPower.gt(playerStart.infinityPower)) popupString+= ",<br> infinity power increased "+shortenMoney(player.infinityPower.log10() - (Decimal.max(playerStart.infinityPower, 1)).log10())+" orders of magnitude"
    if (player.timeShards.gt(playerStart.timeShards)) popupString+= ",<br> time shards increased "+shortenMoney(player.timeShards.log10() - (Decimal.max(playerStart.timeShards, 1)).log10())+" orders of magnitude"
    if (player.infinitied > playerStart.infinitied || player.eternities > playerStart.eternities) popupString+= ","
    else popupString+= "."
    if (player.infinitied > playerStart.infinitied) popupString+= "<br>you infinitied "+(player.infinitied-playerStart.infinitied)+" times."
    if (player.eternities > playerStart.eternities) popupString+= " <br>you eternitied "+(player.eternities-playerStart.eternities)+" times."
    if (popupString.length == 20) {
        popupString = popupString.slice(0, -1);
        popupString+= "... Nothing happened."
        giveAchievement("While you were away... Nothing happened.")
    }

    document.getElementById("offlinePopup").innerHTML = popupString
}

function startInterval() {
    gameLoopIntervalId = setInterval(gameLoop, player.options.updateRate);
}

function enableChart() {
    if (document.getElementById("chartOnOff").checked) {
        player.options.chart.on = true;
        if (player.options.chart.warning < 1) alert("Warning: the chart can cause performance issues. Please disable it if you're experiencing lag.")
    } else {
        player.options.chart.on = false;
    }
}

function enableChartDips() {
    if (document.getElementById("chartDipsOnOff").checked) {
        player.options.chart.dips = true;
    } else {
        player.options.chart.dips = false;
    }
}

function updateChart(first) {
    if (first !== true && (player.infinitied >= 1 || player.eternities >= 1) && player.options.chart.on === true) {
        if (player.currentChallenge == "challenge3" || player.currentChallenge == "postc4") {
            addData(normalDimChart, "0", getDimensionProductionPerSecond(1).times(player.chall3Pow));
        } else {
            addData(normalDimChart, "0", getDimensionProductionPerSecond(1));
        }
    }
    if (player.options.chart.updateRate) {
        setTimeout(updateChart, player.options.chart.updateRate);
    } else {
        setTimeout(updateChart, 1000);
    }
}
updateChart(true);

var slider = document.getElementById("updaterateslider");
var sliderText = document.getElementById("updaterate");

slider.oninput = function() {
    player.options.updateRate = parseInt(this.value);
    sliderText.textContent = "Update rate: " + this.value + "ms"
    if (player.options.updateRate === 200) giveAchievement("You should download some more RAM")
    clearInterval(gameLoopIntervalId);
    gameLoopIntervalId = setInterval(gameLoop, player.options.updateRate);
}

function dimBoolean() {
    var name = TIER_NAMES[getShiftRequirement(0).tier]
    if (!player.autobuyers[9].isOn) return false
    if (player.autobuyers[9].ticks*100 < player.autobuyers[9].interval) return false
	if (player[name + "Amount"] < getShiftRequirement(0).amount) return false
    if (!player.achievements.includes("r28") && player[name + "Amount"] < getShiftRequirement(player.autobuyers[9].bulk-1).amount) return false
    if (player.overXGalaxies <= player.galaxies) return true
    if ((player.currentChallenge =="challenge4" || player.currentChallenge == "postc4") && player.autobuyers[9].priority < getShiftRequirement(0).amount && getShiftRequirement(0).tier == 6) return false
    if (player.autobuyers[9].priority < getShiftRequirement(0).amount && getShiftRequirement(0).tier == 8) return false
    return true
}


function maxBuyGalaxies(manual) {
    if (player.currentEternityChall == "eterc6" || player.currentChallenge == "challenge11" || player.currentChallenge == "postc4" || player.currentChallenge == "postc9"|| player.currentChallenge == "postc7" ) return
    if (player.autobuyers[10].priority > player.galaxies || manual) {
        while(player.eightAmount >= getGalaxyRequirement() && (player.autobuyers[10].priority > player.galaxies || manual)) {
            if (player.options.notation == "Emojis") player.spreadingCancer+=1;
            player.galaxies++
        }
        player.galaxies--
        galaxyReset()
    }
}

function maxBuyDimBoosts(manual) {
    if (player.autobuyers[9].priority > player.resets || player.overXGalaxies <= player.galaxies || getShiftRequirement(0).tier < 8 || manual == true) {
        var r = 0;
        while(player[TIER_NAMES[getShiftRequirement(r).tier]+"Amount"] >= getShiftRequirement(r).amount && (player.autobuyers[9].priority > player.resets+r || player.overXGalaxies <= player.galaxies || getShiftRequirement(r).tier < 8 || manual == true)) r+=1;

        if (r >= 750) giveAchievement("Costco sells dimboosts now")
        if (r > 0) softReset(r)
    }

}

var timer = 0
function autoBuyerTick() {

    if (player.eternities >= 100 && player.eternityBuyer.isOn && gainedEternityPoints().gte(player.eternityBuyer.limit)) eternity(false, true)

    if (player.autobuyers[11]%1 !== 0) {
    if (player.autobuyers[11].ticks*100 >= player.autobuyers[11].interval && player.money.gte(Number.MAX_VALUE)) {
        if (player.autobuyers[11].isOn) {
            if (player.autoCrunchMode == "amount") {
                if (!player.break || player.currentChallenge != "" || player.autobuyers[11].priority.lt(gainedInfinityPoints())) {
                    autoS = false;
                    document.getElementById("bigcrunch").click()
                }
            } else if (player.autoCrunchMode == "time"){
                if (!player.break || player.currentChallenge != "" || player.autobuyers[11].priority.lt(player.thisInfinityTime/10)) {
                    autoS = false;
                    document.getElementById("bigcrunch").click()
                }
            } else {
                if (!player.break || player.currentChallenge != "" || gainedInfinityPoints().gte(player.lastTenRuns[0][1].times(player.autobuyers[11].priority))) {
                    autoS = false;
                    document.getElementById("bigcrunch").click()
                }
            }
            player.autobuyers[11].ticks = 1;
        }
    } else player.autobuyers[11].ticks += 1;

    }


    if (player.autobuyers[10]%1 !== 0) {
        if (player.autobuyers[10].ticks*100 >= player.autobuyers[10].interval && (player.currentChallenge == "challenge4" ? player.sixthAmount >= getGalaxyRequirement() : player.eightAmount >= getGalaxyRequirement())) {
            if (player.eternities < 9 || player.autobuyers[10].bulk == 0) {
                if (player.autobuyers[10].isOn && player.autobuyers[10].priority > player.galaxies) {
                    autoS = false;
                    document.getElementById("secondSoftReset").click()
                    player.autobuyers[10].ticks = 1;
                }
            } else if (player.autobuyers[10].isOn && (Math.round(timer * 100))%(Math.round(player.autobuyers[10].bulk * 100)) == 0){
                maxBuyGalaxies()
            }
        } else player.autobuyers[10].ticks += 1;
    }


    if (player.autobuyers[9]%1 !== 0) {
        if (dimBoolean()) {
            if (player.resets < 4 || !player.infinityUpgrades.includes("bulkBoost")) {
                softReset(1);
                player.autobuyers[9].ticks = 0
            } else if (!player.achievements.includes("r28")) {
                softReset(player.autobuyers[9].bulk);
                player.autobuyers[9].ticks = 0
            } else if ((Math.round(timer * 100))%(Math.round(player.autobuyers[9].bulk * 100)) == 0 && player.eightAmount >= getShiftRequirement(0).amount) {
                maxBuyDimBoosts();
                player.autobuyers[9].ticks = 0
            }
        }
        player.autobuyers[9].ticks += 1;
    }

    if (player.autobuyers[12]%1 !== 0) {
        if (calcSacrificeBoost().gte(player.autobuyers[12].priority) && player.autobuyers[12].isOn) {
            sacrifice(true)
        }
    }

    if (player.autobuyers[13]%1 !== 0) {
        if (getGSAmount().gte(player.autobuyers[13].priority) && player.autobuyers[13].isOn) {
            galacticSacrifice();
        }
    }






    for (var i=0; i<priority.length; i++) {
        if (priority[i].ticks*100 >= priority[i].interval || priority[i].interval == 100) {
            if ((priority[i].isOn && canBuyDimension(priority[i].tier)) ) {
                if (priority[i] == player.autobuyers[8] ) {
                    if (priority[i].target == 10) {
                      if (player.currentChallenge !== 'challenge14') buyMaxTickSpeed();
                    }
                    else {
                      buyTickSpeed()
                    }
                } else {
                    if (priority[i].target > 10) {
                        if (player.options.bulkOn) buyManyDimensionAutobuyer(priority[i].target-10, priority[i].bulk)
                        else buyManyDimensionAutobuyer(priority[i].target-10, 1)
                    }
                    else {
                        buyOneDimension(priority[i].target)
                    }
					if(player.achievements.includes("r52"))if (player.options.bulkOn)autobuyerBuyTimeDimensions(priority[i].target%10, priority[i].bulk)
					else autobuyerBuyTimeDimensions(priority[i].target%10, 1)
                }
                priority[i].ticks = 0;
            }
        } else priority[i].ticks += 1;
    }
    updateCosts()

}


setInterval(function() {
    timer += 0.05
    if (!player.infinityUpgrades.includes("autoBuyerUpgrade")) autoBuyerTick()
}, 100)

setInterval(function() {
    if (player.infinityUpgrades.includes("autoBuyerUpgrade")) autoBuyerTick()
}, 50)


  //start scrolling
  scrollNextMessage();

document.getElementById("challenge2").onclick = function () {
  startChallenge("challenge2", Number.MAX_VALUE)
}

document.getElementById("challenge3").onclick = function () {
  startChallenge("challenge3", Number.MAX_VALUE)
}

document.getElementById("challenge4").onclick = function () {
  startChallenge("challenge4", Number.MAX_VALUE)
}

document.getElementById("challenge5").onclick = function () {
  startChallenge("challenge5", Number.MAX_VALUE);
}

document.getElementById("challenge6").onclick = function () {
  startChallenge("challenge6", Number.MAX_VALUE);
}

document.getElementById("challenge7").onclick = function () {
  startChallenge("challenge7", Number.MAX_VALUE);
}

document.getElementById("challenge8").onclick = function () {
  startChallenge("challenge8", Number.MAX_VALUE);
}

document.getElementById("challenge9").onclick = function () {
  startChallenge("challenge9", Number.MAX_VALUE);
}

document.getElementById("challenge10").onclick = function () {
  startChallenge("challenge10", Number.MAX_VALUE);
}

document.getElementById("challenge11").onclick = function () {
    startChallenge("challenge11", Number.MAX_VALUE);
  }

document.getElementById("challenge12").onclick = function () {
  startChallenge("challenge12", Number.MAX_VALUE);
}

document.getElementById("challenge13").onclick = function () {
  startChallenge("challenge13", Number.MAX_VALUE);
}

document.getElementById("challenge14").onclick = function () {
  startChallenge("challenge14", Number.MAX_VALUE);
}



function showInfTab(tabName) {
    //iterate over all elements in div_tab class. Hide everything that's not tabName and show tabName
    var tabs = document.getElementsByClassName('inftab');
    var tab;
    for (var i = 0; i < tabs.length; i++) {
        tab = tabs.item(i);
        if (tab.id === tabName) {
            tab.style.display = 'block';
        } else {
            tab.style.display = 'none';
        }
    }
}

function showStatsTab(tabName) {
    //iterate over all elements in div_tab class. Hide everything that's not tabName and show tabName
    var tabs = document.getElementsByClassName('statstab');
    var tab;
    for (var i = 0; i < tabs.length; i++) {
        tab = tabs.item(i);
        if (tab.id === tabName) {
            tab.style.display = 'block';
        } else {
            tab.style.display = 'none';
        }
    }
}

function showDimTab(tabName) {
    //iterate over all elements in div_tab class. Hide everything that's not tabName and show tabName
    var tabs = document.getElementsByClassName('dimtab');
    var tab;
    for (var i = 0; i < tabs.length; i++) {
        tab = tabs.item(i);
        if (tab.id === tabName) {
            tab.style.display = 'block';
        } else {
            tab.style.display = 'none';
        }
    }
    if (tabName === 'antimatterdimensions') document.getElementById("progress").style.display = "block"
    else document.getElementById("progress").style.display = "none"
}

function showChallengesTab(tabName) {
    //iterate over all elements in div_tab class. Hide everything that's not tabName and show tabName
    var tabs = document.getElementsByClassName('challengeTab');
    var tab;
    for (var i = 0; i < tabs.length; i++) {
        tab = tabs.item(i);
        if (tab.id === tabName) {
            tab.style.display = 'block';
        } else {
            tab.style.display = 'none';
        }
    }
}

function showEternityTab(tabName, init) {
    //iterate over all elements in div_tab class. Hide everything that's not tabName and show tabName
    var tabs = document.getElementsByClassName('eternitytab');
    var tab;
    for (var i = 0; i < tabs.length; i++) {
        tab = tabs.item(i);
        if (tab.id === tabName) {
            tab.style.display = 'block';
        } else {
            tab.style.display = 'none';
        }
    }
    if (tabName === 'timestudies' && !init) document.getElementById("TTbuttons").style.display = "block"
    else document.getElementById("TTbuttons").style.display = "none"
    resizeCanvas()
}

function showAchTab(tabName) {
    //iterate over all elements in div_tab class. Hide everything that's not tabName and show tabName
    var tabs = document.getElementsByClassName('achtab');
    var tab;
    for (var i = 0; i < tabs.length; i++) {
        tab = tabs.item(i);
        if (tab.id === tabName) {
            tab.style.display = 'block';
        } else {
            tab.style.display = 'none';
        }
    }
}




function init() {
    console.log('init');

    //setup the onclick callbacks for the buttons
    document.getElementById('dimensionsbtn').onclick = function () {
        showTab('dimensions');
    };
    document.getElementById('optionsbtn').onclick = function () {
        showTab('options');
    };
    document.getElementById('statisticsbtn').onclick = function () {
        showTab('statistics');
    };
    document.getElementById('achievementsbtn').onclick = function () {
        showTab('achievements');
    };
    document.getElementById('challengesbtn').onclick=function () {
      showTab('challenges');
    };
    document.getElementById('galaxybtn').onclick= function () {
        showTab('galaxy')
    }
    document.getElementById('infinitybtn').onclick = function () {
        showTab('infinity');
    };
    document.getElementById("shopbtn").onclick = function () {
        showTab('shop')
        updateKongPurchases()
    }
    document.getElementById("eternitystorebtn").onclick = function () {
        showTab('eternitystore')
    }
    document.getElementById("interrealitybtn").onclick = function () {
        showTab('interrealitytab')
    }
    //show one tab during init or they'll all start hidden
    showTab('dimensions')
    showInfTab('preinf')
    showStatsTab('stats')
    showDimTab('antimatterdimensions')
    showChallengesTab('challenges')
    showEternityTab('timestudies', true)
    load_game();
    updateTickSpeed();
    updateAutobuyers();
    updateChallengeTimes()
    try {
        kongregateAPI.loadAPI(function () {
            window.kongregate = kongregateAPI.getAPI();
        });
        updateKongPurchases()
    } catch (err) {console.log("Couldn't load Kongregate API")}

    //if (typeof kongregate === 'undefined') document.getElementById("shopbtn").style.display = "none"

}









//Playfab stuff



function closeToolTip() {
    var elements = document.getElementsByClassName("popup")
    for (var i=0; i<elements.length; i++) elements[i].style.display = "none"
}

function tooltipLoad() {
    loadFromPlayFab()
    closeToolTip()
}

function tooltipSave() {
    saveToPlayFab()
    closeToolTip()
}



setInterval(function () {
    save_game()
}, 30000);

setInterval(function () {
    if (playFabId != -1 && player.options.cloud) playFabSaveCheck();
}, 1000*60*5)
updateCosts();
//updateInterval();
updateDimensions();
updateChallenges();
document.getElementById("hiddenheader").style.display = "none";


window.onload = function() {
    startInterval()
    setTimeout(function() {
        playFabLogin();
        updateKongPurchases()
        try {
            if (kongregate.services.getGameAuthToken() === undefined) document.getElementById("shopbtn").style.display = "none"
        } catch(e) {
            console.log(e)
            document.getElementById("shopbtn").style.display = "none"
        }
        document.getElementById("container").style.display = "block"
        document.getElementById("loading").style.display = "none"
    }, 1000)

}

window.addEventListener('keydown', function(event) {
    if (keySequence == 0 && event.keyCode == 38) {
        keySequence++
    } else if (keySequence == 1 && event.keyCode == 38) {
        keySequence++
    } else if (keySequence == 2 && event.keyCode == 40) {
        keySequence++
    } else if (keySequence == 3 && event.keyCode == 40) {
        keySequence++
    } else if (keySequence == 4 && event.keyCode == 37) {
        keySequence++
    } else if (keySequence == 5 && event.keyCode == 39) {
        keySequence++
    } else if (keySequence == 6 && event.keyCode == 37) {
        keySequence++
    } else if (keySequence == 7 && event.keyCode == 39) {
        keySequence++
    } else if (keySequence == 8 && event.keyCode == 66) {
        keySequence++
    } else if (keySequence == 9 && event.keyCode == 65) {
        giveAchievement("30 Lives")
    } else {
        keySequence = 0;
    }
    if (event.keyCode == 17) controlDown = true;
    if (event.keyCode == 16) {
        shiftDown = true;
        document.getElementById("studytreeloadsavetext").textContent = "save:"
        drawStudyTree()
    }
    if ((controlDown && shiftDown && (event.keyCode == 67 || event.keyCode == 73 || event.keyCode == 74)) || event.keyCode == 123) {
        giveAchievement("Stop right there criminal scum!")
    }
}, false);

window.addEventListener('keyup', function(event) {
    if (event.keyCode == 17) controlDown = false;
    if (event.keyCode == 16) {
        shiftDown = false;
        document.getElementById("studytreeloadsavetext").textContent = "load:"
        drawStudyTree()
    }
}, false);

window.onfocus = function() {
    controlDown = false;
    shiftDown = false;
    document.getElementById("studytreeloadsavetext").textContent = "load:"
    drawStudyTree()
}

window.addEventListener('keydown', function(event) {
    if (!player.options.hotkeys || controlDown === true || document.activeElement.type === "text") return false
    const tmp = event.keyCode;
    if (tmp >= 49 && tmp <= 56) {
        if (shiftDown) buyOneDimension(tmp-48)
        else buyManyDimension(tmp-48)
        return false;
    } else if (tmp >= 97 && tmp <= 104) {
        if (shiftDown) buyOneDimension(tmp-96)
        else buyManyDimension(tmp-96)
        return false;
    }
    switch (event.keyCode) {
        case 65: // A
            toggleAutoBuyers();
        break;

        case 68: // D
            document.getElementById("softReset").onclick()
        break;

        case 71: // G
            document.getElementById("secondSoftReset").onclick()
        break;

        case 77: // M
            document.getElementById("maxall").onclick()
            
  for(var i=1; i<9; i++) while(buyTimeDimensionAntimatter(i,1)) continue
        break;

        case 83: // S
            document.getElementById("sacrifice").onclick()
        break;

        case 84: // T
            if (shiftDown) buyTickSpeed()
            else buyMaxTickSpeed()
        break;

        case 82: //R
            replicantiGalaxy()
        break;
    }
  }, false);

  window.addEventListener('keyup', function(event) {
    if (event.keyCode === 70) {
        $.notify("Paying respects", "info")
        giveAchievement("It pays to have respect")
    }
    if (!player.options.hotkeys || controlDown === true || document.activeElement.type === "text") return false
    switch (event.keyCode) {
        case 67: // C
            document.getElementById("bigcrunch").onclick()
        break;

        case 69: // E, also, nice.
        document.getElementById("eternitybtn").onclick();
        break;

    }
  }, false);




init();
var totalMult = 1
var currentMult = 1
var infinitiedMult = 1
var achievementMult = 1
var challengeMult = 1
var unspentBonus = 1
var postc10Mult = new Decimal(0)
var mult18 = 1
var ec10bonus = new Decimal(1)
var timeMultNum = 1
var timeMultNum2 = 1

setInterval( function() {
    totalMult = Math.pow(player.totalmoney.e+1, 2)
    currentMult = Math.pow(player.money.e+1, 2)
    if (player.timestudy.studies.includes(31)) infinitiedMult = 1 + Math.pow(Math.log10(getInfinitied()+1)*100, 8)
    else infinitiedMult = Math.pow(1+Math.log10(getInfinitied()+1)*100,2)
    achievementMult = Math.max(Math.pow((player.achievements.length-10-getSecretAchAmount()), 5)/40,1)
    challengeMult = Decimal.max(Math.pow(10*3000/worstChallengeTime, 2), 1)
    unspentBonus = getUnspentIPBonus();
    mult18 = getDimensionFinalMultiplier(1).times(getDimensionFinalMultiplier(8)).pow(0.02)
    if (player.currentEternityChall == "eterc10") {
        ec10bonus = Decimal.pow(getInfinitied(), 1000).max(1)
    } else {
        ec10bonus = new Decimal(1)
    }
    timeMultNum = Math.max(Math.pow(1 + player.totalTimePlayed / 864000, 0.75), 1);
    timeMultNum2 = Math.max(Math.pow(1 + player.thisInfinityTime / 2400, 1.5), 1)
	
	document.getElementById("scND").innerHTML = "Normal dimension multipliers and tickspeed are dilated "+(player.dilation.active?"twice ":"")+"after " + shorten(Decimal.pow(10,getDilationStart())) +". <br>Normal dimension multipliers are dilated again after "+ shorten(Decimal.pow(10,getDilationStart2()))+". <br>Normal dimension multipliers are dilated again after "+ shorten(Decimal.pow(10,getDilationStart3()))+". <br>Normal dimension multipliers "+(player.timeless.upgrades.includes(25)?"":"and tickspeed ")+"are dilated again after "+ shorten(Decimal.pow(10,getDilationStart4()))+".";
	document.getElementById("scID").innerHTML = "Infinity dimension multipliers and Infinity Power are dilated "+(player.dilation.active?"twice ":"")+"after " + shorten(Decimal.pow(10,getDilationStart())) +". <br>Infinity dimension multipliers are dilated again after "+ shorten(Decimal.pow(10,getDilationStart4()))+".";
	document.getElementById("scTLP").innerHTML = "Timeless Point gain is dilated "+(player.dilation.active?"twice ":"")+"after " + shorten(Decimal.pow(10,getDilationStart())) +".";
	document.getElementById("scDT").innerHTML = "Dilated Time gain is dilated "+(player.dilation.active?"twice ":"")+"after " + shorten(Decimal.pow(10,getDilationStart())) +".";
	//document.getElementById("scMD").innerHTML = "Meta dimension multipliers are dilated "+(player.dilation.active?"twice ":"")+"after " + shorten(Decimal.pow(10,getDilationStart())) +".";
	
        var timeShiftRequirement = getTimeShiftRequirement(0);
        var tickspeedShiftRequirement = getTickspeedShiftRequirement(0);
        if (player.tdBoosts < 7) {
            document.getElementById("timeBoostLabel").textContent = 'Time Dimension Shift ('+ player.tdBoosts +'): requires ' + timeShiftRequirement.amount + " " + DISPLAY_NAMES[timeShiftRequirement.tier] + " Time Dimensions"
        }
        else document.getElementById("timeBoostLabel").textContent = 'Time Dimension Boost ('+ player.tdBoosts +'): requires ' + timeShiftRequirement.amount + " " + DISPLAY_NAMES[timeShiftRequirement.tier] + " Time Dimensions"

        document.getElementById("tickspeedResetLabel").textContent = tickspeedShiftRequirement.prefix + 'Tickspeed Boost ('+ player.tickspeedBoosts +'): requires ' + tickspeedShiftRequirement.amount + " " + DISPLAY_NAMES[tickspeedShiftRequirement.tier] + " Dimensions"

    
	
	while(player.tdBoosts < Math.min(player.eternities,5)*4){
		player.tdBoosts++;
	}
	while(player.infinityUpgrades.includes("skipReset3") && player["timeDimension"+getTimeShiftRequirement(0).tier].bought+player["timeDimension"+getTimeShiftRequirement(0).tier].boughtAntimatter >= getTimeShiftRequirement(0).amount){
		player.tdBoosts++;
	}
	while(player.infinityUpgrades.includes("skipResetGalaxy") && player["eightAmount"] >= getTickspeedShiftRequirement(0).amount){
		player.tickspeedBoosts++;
	}
	if(player["eightAmount"] >= getTickspeedShiftRequirement(0).amount)document.getElementById("tickspeedSoftReset").className="storebtn";else document.getElementById("tickspeedSoftReset").className="unavailablebtn";
	if(player["timeDimension"+getTimeShiftRequirement(0).tier].bought+player["timeDimension"+getTimeShiftRequirement(0).tier].boughtAntimatter >= getTimeShiftRequirement(0).amount)document.getElementById("timeSoftReset").className="storebtn";else document.getElementById("timeSoftReset").className="unavailablebtn";
	document.getElementById("postcngm4r_2div").style.display=player.challenges.includes("postcngm3_3")?"":"none";
	document.getElementById("replicantiICrow").style.display=player.achievements.includes("r95")?"":"none";
	document.getElementById("forceRespecStudy").style.display=player.eternities>0?"":"none";
	document.getElementById("forceRespecStudy1").innerHTML=player.infinityPoints.gte(Number.MAX_VALUE)?"Respec time studies and eternity":"Respec time studies and restart this eternity"
	document.getElementById("postcngm4r_1reward").innerHTML="Reward: Boost odd tiers of Normal and Time Dimensions based on GP."+(player.timeless.active?" (Disabled in Timeless)":" (GP+1)^10");
	if(player.achievements.length-getSecretAchAmount()>=100)giveAchievement("Meta-achievement");
}, 100)

function forceRespecStudy(){
	if(player.infinityPoints.gte(Number.MAX_VALUE) && player.currentEternityChall === ""){
		if(confirm("Are you sure you want to respec study tree and eternity?")){
			player.respec=true
			eternity(false,true);
		}
	}else if(confirm("Are you sure you want to respec study tree and restart this eternity?")){
		player.respec=true
		eternity(true);
	}
}

function TLPU4(){
	return player.timeless.points.add(1).pow(0.2);
}

function TLPU5(){
	if(player.timeless.active)return player.timeless.points.add(1).pow(10);
	return player.timeless.points.add(1).pow(1000);
}

function TLPU21(){
	return player.timeless.points.add(1).pow(10000);
}

function TLPU26(){
	return Math.sqrt(player.timeless.shards.add(10).log10());
}

function TLPU29(){
	let totalbought=0
for(i = 1;i <= 8; i++){
	totalbought=totalbought+player["timeDimension"+i].bought+player["timeDimension"+i].boughtAntimatter;
}
return Decimal.pow(2,totalbought);
}

function TLPU30(){
	return player.timeless.points.add(1).pow(10000);
}

function EC1Reward(){
	let power=500*ECTimesCompleted("eterc1");
	if(player.timeless.active)power=5*ECTimesCompleted("eterc1");
	let ret=Decimal.pow(Math.max(player.thisEternity*10, 1),power);
	return ret;
}

function EC2Reward(){
	let ret=new Decimal(player.infinityPower.plus(10).log10()).pow(5000*ECTimesCompleted("eterc2")).times(player.infinityPower.pow(0.005*ECTimesCompleted("eterc2"))).max(1)
	return ret;
}

function EC4Reward(){
	let ret=player.infinityPoints.add(1).pow(ECTimesCompleted("eterc4")*3)
	return ret;
}

function EC9Reward(){
	let ret=player.timeShards.add(1).pow(ECTimesCompleted("eterc9")*0.01);
	return ret;
}
function EC10Reward(){
	let power=500*ECTimesCompleted("eterc10");
	if(player.timeless.active)power=5*ECTimesCompleted("eterc10");
	let ret=Decimal.pow(Math.max(getInfinitied(), 1),power);
	return ret;
}
function EU8Effect(){
	let ret=new Decimal(1);
  if (player.eternityUpgrades.includes(4)) ret = ret.times(player.achPow)
  if (player.eternityUpgrades.includes(5)) ret = ret.times(Math.max(player.timestudy.theorem, 1))
  if (player.eternityUpgrades.includes(6)) ret = ret.times(player.totalTimePlayed / 10 / 60 / 60 / 24)
  if (player.achievements.includes("ngm4r5")) ret = ret.pow(2);
	  return ret.pow(0.2);
}